docker 版本: Version 17.03.1-ce-mac12 (17661)
nginx 镜像版本 latest(1.13.1)
宿主机内网 IP:192.168.1.101
手机内网 IP:192.168.1.103
> docker run -d -p 8080:80 --name httpd nginx:latest
在宿主机上访问 http://192.168.1.101:8080
在手机上访问 http://192.168.1.101:8080
> docker logs httpd
172.17.0.1 - - [23/Jun/2017:14:36:00 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.51.0" "-"
172.17.0.1 - - [23/Jun/2017:14:36:41 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 ..." "-"
同样的命令在 linux 宿主机上不会出现这问题
1
neilp 2017-06-23 22:47:22 +08:00
楼主是用的 docker on Windows 10 吗
我之前装这个后, 貌似主机的 tracert 就无法工作了. 麻烦楼主在主机上试试 tracert ``` tracert www.baidu.com ``` |
2
htfy96 2017-06-23 22:59:37 +08:00
docker 做了 SNAT,最简单的做法是 docker run -d -p 8080:80 --net host --name httpd nginx:latest
|
3
fuxkcsdn OP @neilp 安装的是 docker for windows,主机系统是 windows 10,刚测试 主机的 tracert 是正常的
@htfy96 用 --net host 后访问不了呢... > docker run -d -p 8080:80 --net host --name httpd nginx:latest 7dfdffecfaa61b22a0a0113cd461a2414cacf3c87cea437cba833d62281b7228 > curl 127.0.0.1 curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused > curl 127.0.0.1:8080 curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused > curl 192.168.1.101:8080 curl: (7) Failed to connect to 192.168.1.101 port 8080: Connection refused > curl 192.168.1.101:80 curl: (7) Failed to connect to 192.168.1.101 port 80: Connection refused > docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7dfdffecfaa6 nginx:latest "nginx -g 'daemon ..." 22 seconds ago Up 21 seconds httpd |
4
xoxo419 2018-09-10 11:29:31 +08:00
哈喽, 这个问题现在有解决的方法了么
|
5
xoxo419 2018-09-15 15:15:56 +08:00
MAC- 只能获取容器的 IP. 但是 Linux 上可以获取到客户端的真实 IP [关于问题相关的资料]( http://www.majianwei.com/archives/7909)
|