{"id":5152,"date":"2018-10-12T17:14:00","date_gmt":"2018-10-12T09:14:00","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=5152"},"modified":"2023-04-14T16:04:57","modified_gmt":"2023-04-14T08:04:57","slug":"docker-%e7%b6%b2%e5%9d%80%e8%bd%89-port","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=5152","title":{"rendered":"Docker - \u7db2\u5740\u8f49 Port"},"content":{"rendered":"<p>\u4f7f\u7528 Docker \u5728\u4e00\u53f0\u4e3b\u6a5f\u4e0a\u57f7\u884c\u591a HTTP Service\uff0c\u56e0\u70ba\u9700\u8981 Port \u5c0d\u5916\uff0c\u5982\u679c\u770b\u4e0d\u61c2\u7db2\u8def\u5176\u4ed6\u7684\u8a2d\u5b9a\u4e0d\u59a8\u53c3\u8003 Hoyo \u7684\u601d\u8def<\/p>\n<p>Hoyo \u7684\u4f5c\u6cd5\u662f\u4f7f\u7528\u4e00\u53f0 Docker container \u5b89\u88dd Nginx \u4f86\u63d0\u4f9b Proxy Pass \u529f\u80fd\uff0c\u5c07\u7db2\u5740\u76f4\u63a5\u8f49\u5230 container\u3002<\/p>\n<p>\u6b64\u65b9\u6cd5\u7684\u597d\u8655\u662f\uff0c\u65b0\u589e\u5b50 HTTP Service \u53ea\u9808 docker run \u4e0d\u9700\u8981\u8a2d\u5b9a\u5176\u4ed6\u7db2\u8def\u8a2d\u5b9a\uff0c\u5c0d\u65bc Nginx \u53ea\u9700\u8981\u65b0\u589e conf \u91cd\u65b0\u555f\u52d5 nginx service \u5f8c\u5373\u53ef\u555f\u7528\uff0c\u4e5f\u4e0d\u9700\u8981\u8b8a\u66f4 container<\/p>\n<p>--<\/p>\n<h2>Nginx container<\/h2>\n<p>Nginx \u7684\u4e3b\u6a5f\u9078\u64c7\u7684\u662f Debian Linux \uff0c\u6240\u4ee5\u9808\u5148 pull \u4e00\u500b debian \u74b0\u5883\uff0c\u5728\u6b64\u4f7f\u7528\u7684\u662f debian:9 \uff0c\u7136\u5f8c\u662f\u5b89\u88dd nginx<\/p>\n<ul>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-nginx-on-debian-9\" target=\"_blank\" rel=\"noopener\">How To Install Nginx on Debian 9<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\"># apt install -y nginx<\/pre>\n<p>--<\/p>\n<h2>\u5b50 HTTP Service container<\/h2>\n<p>\u5be6\u969b\u63d0\u4f9b HTTP \u670d\u52d9\u7684\u5bb9\u5668\uff0c\u4f7f\u7528\u7684\u4e5f\u662f Debian:9 \uff0c\u7136\u5f8c\u5b89\u88dd\u7684\u662f Apache 2.4 \u85c9\u4ee5\u548c Proxy Pass \u5340\u9694\uff0c\u7576\u7136\u4f7f\u7528 Nginx \u4e5f\u53ef\u4ee5<\/p>\n<p>--<\/p>\n<h2>\u5b50 WWW \u555f\u52d5<\/h2>\n<p>\u5b50 WWW \u555f\u52d5\u4e0d\u9700\u8981\u555f\u52d5 port \u5c0d\u61c9<\/p>\n<pre class=\"lang:default decode:true\"># docker run --name=\"www1\" -d hoyo\/httpd:v6<\/pre>\n<p>\u67e5\u8a62 contriner IP address<\/p>\n<pre class=\"lang:default decode:true\"># docker inspect www1 | grep IPAddress\r\n            \"SecondaryIPAddresses\": null,\r\n            \"IPAddress\": \"172.17.0.2\",\r\n                    \"IPAddress\": \"172.17.0.2\",\r\n<\/pre>\n<ul style=\"color: #333333; font-style: normal; line-height: 24.375px;\">\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/17157721\/how-to-get-a-docker-containers-ip-address-from-the-host\" target=\"_blank\" rel=\"noopener\">How to get a Docker container's IP address from the host?<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \"># docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)\r\n\/www2 - 172.17.0.4\r\n\/nginx - 172.17.0.3\r\n\/www1 - 172.17.0.2<\/pre>\n<p>--<\/p>\n<h2>\u4f7f\u7528 Nginx \u5c07\u591a container WWW \u670d\u52d9\u8f49\u5230\u7db2\u5740<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/questions\/how-do-i-point-my-custom-domain-to-my-ip-port-41-111-20-36-8080\" target=\"_blank\" rel=\"noopener\">How do I point my custom domain to my IP:Port (41.111.20.36:8080)?<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\"># docker run --name=\"nginx\" -p 80:80 -itd  debian\/nginx:v1 bash<\/pre>\n<p>vi \/etc\/nginx\/sites-available\/www1<\/p>\n<pre class=\"lang:default decode:true\">server {\r\n    listen 80;\r\n    server_name www1.hoyo.idv.tw;\r\n\r\n    location \/ {\r\n        proxy_set_header Host $host;\r\n        proxy_pass http:\/\/172.17.0.2;\r\n    }\r\n}<\/pre>\n<p>\u5c07\u9700\u8981\u555f\u52d5\u7684\u7db2\u7ad9\u9023\u7d50\u5230\u00a0sites-enabled<\/p>\n<pre class=\"lang:default decode:true \"># ln -s \/etc\/nginx\/sites-available\/www1 \/etc\/nginx\/sites-enabled\/www1<\/pre>\n<p>\u91cd\u65b0\u555f\u52d5 Nginx<\/p>\n<pre class=\"lang:default decode:true\"># nginx -s reload<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"5152\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,589&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Docker \u5728\u4e00\u53f0\u4e3b\u6a5f...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"5152\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,589&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[333],"tags":[296],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5152"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5152"}],"version-history":[{"count":10,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5152\/revisions"}],"predecessor-version":[{"id":10969,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5152\/revisions\/10969"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}