[root@localhost ~]# curl 172.17.0.3 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>
[root@localhost ~]# docker exec -it nginx_c_b1 /bin/bash root@c19004406443:/# curl 172.17.0.3 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>
#查看系统路由表 [root@localhost ~]# ip route default via 172.27.47.253 dev eth0 proto dhcp metric 100 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 172.27.32.0/20 dev eth0 proto kernel scope link src 172.27.45.106 metric 100
# 重新用名称访问成功 [root@localhost ~]# docker exec -it nginx_c_b3 curl nginx_c_b2 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>
# 反过来用名称访问也是不行的 [root@localhost ~]# docker exec -it nginx_c_b2 curl nginx_c_b3 curl: (6) Could not resolve host: nginx_c_b3
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c234f7622275 nginx "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 80/tcp nginx_c_b3 edb46469326c nginx "/docker-entrypoint.…" 35 minutes ago Up 35 minutes 0.0.0.0:8562->80/tcp, :::8562->80/tcp nginx_c_b2 41abcb9be1b3 nginx "/docker-entrypoint.…" 35 minutes ago Up 35 minutes 0.0.0.0:8561->80/tcp, :::8561->80/tcp nginx_c_b1