• 欢迎访问运维搬运工网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 本站一年会员:100元 ,两年会员:180元 ,永久会员:380元
  • 这世界就是,一些人总在昼夜不停地运转,而另外一些人,起床就发现世界已经变了。
  • 本博客推广的是知识付费,用赞助的方式实现博客维护,不以赚钱为目的的博客

docker网络访问

随机映射

[root@instance-7tgaowaa ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ae513a47849c 3 weeks ago 109MB
centos latest e934aafc2206 7 weeks ago 199MB
[root@instance-7tgaowaa ~]# docker run -d -P --name nginx-test1 nginx
f81ca5b35eed8c110fa40cf4be83d05b56ad46639d9579f7893e2038367c881a

-d后台运行 -P随机端口 –name 给容器起名 nginx镜像名称

验证

[root@instance-7tgaowaa ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f81ca5b35eed nginx "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:32768->80/tcp nginx-test1
[root@instance-7tgaowaa ~]# ss -tnlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port 
LISTEN 0 128 *:22 *:* users:(("sshd",pid=1142,fd=3))
LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=971,fd=13))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=1142,fd=4))
LISTEN 0 100 ::1:25 :::* users:(("master",pid=971,fd=14))
LISTEN 0 128 :::32768 :::* users:(("docker-proxy",pid=27549,fd=4))

 

 

查看这个容器的日志

[root@instance-7tgaowaa ~]# docker logs nginx-test1 
210.12.126.94 - - [28/May/2018:10:37:16 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3423.2 Safari/537.36" "-"
210.12.126.94 - - [28/May/2018:10:37:17 +0000] "GET /favicon.ico HTTP/1.1" 404 572 "http://180.76.189.187:32768/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3423.2 Safari/537.36" "-"
2018/05/28 10:37:17 [error] 7#7: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 210.12.126.94, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "180.76.189.187:32768", referrer: "http://180.76.189.187:32768/"
210.12.126.94 - - [28/May/2018:10:37:29 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063" "-"
140.207.54.197 - - [28/May/2018:10:38:16 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36" "-"

指定端口映射

[root@instance-7tgaowaa ~]# docker run -d -p 88:80 --name nginx-test2 nginx
123501e0996b2c4724a4eb578c8607cf1903848bd001e5b7afef5b9760d1ada9
[root@instance-7tgaowaa ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
123501e0996b nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 0.0.0.0:88->80/tcp nginx-test2
[root@instance-7tgaowaa ~]# ss -tnlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port 
LISTEN 0 128 *:22 *:* users:(("sshd",pid=1142,fd=3))
LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=971,fd=13))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=1142,fd=4))
LISTEN 0 128 :::88 :::* users:(("docker-proxy",pid=27678,fd=4))
LISTEN 0 100 ::1:25 :::* users:(("master",pid=971,fd=14))
LISTEN 0 128 :::32768 :::* users:(("docker-proxy",pid=27549,fd=4))

指定ip和端口映射

[root@instance-7tgaowaa ~]# docker run -d -p 192.168.56.11:89:80 --name nginx-test4 nginx 
50d31d0581cf5c25eaa61f05fb3087c7bddcf0441fd2ed0f00ed6a6d2ce575ce

运维搬运工 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:docker网络访问
喜欢 (1)
[扫描二维码]
分享 (0)
大自然搬运工
关于作者:
不是路不平,而是你不行。到底行不行,看你停不停。只要你不停,早晚都能行。
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址