docker网络-如何让外部网络访问容器资源
安装httpd 服务:
docker:/root# docker exec -it f63b2633d146 bash
bash-4.1# yum install httpd
Loaded plugins: fastestmirror
docker:/root# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
107d8291c6bc 192.168.32.150:5000/zjzc_centos6.5_m1 "bash" 3 hours ago Up 3 hours prickly_colden
99037e5ed32e 192.168.32.150:5000/zjzc_centos6.5_template "bash" 4 hours ago Up 4 hours zjtest02
f63b2633d146 192.168.32.150:5000/zjzc_centos6.5_template "bash" 4 hours ago Up 4 hours zjtest01
docker commit -m "zjzc_centos6.5-m2" -a scan 1a177b16d2a6 192.168.32.150:5000/zjzc_centos6.5_m1
docker:/root# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
107d8291c6bc 192.168.32.150:5000/zjzc_centos6.5_m1 "bash" 3 hours ago Up 3 hours prickly_colden
99037e5ed32e 192.168.32.150:5000/zjzc_centos6.5_template "bash" 5 hours ago Up 5 hours zjtest02
f63b2633d146 192.168.32.150:5000/zjzc_centos6.5_template "bash" 5 hours ago Up 5 hours zjtest01
docker:/root#
docker:/root# docker commit -m "zjzc_centos6.5-m2" -a scan f63b2633d146 zjzc_centos6.5_m2
fbce1a72323329e3ce2831652f0b173056ef1111485f4d4a5a1afb6358955608
docker run -itd -p5123:80 centos-httpd bash
左边的端口是宿主机的端口 右边是docker容器的端口
docker:/root# docker run -itd -p 5123:80 zjzc_centos6.5_m2 bash
d0339cedbb2915c678a47760d4d23bf8b3f24f813f3e084413cb0624a0abe4eb
docker:/root# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d0339cedbb29 zjzc_centos6.5_m2 "bash" 3 seconds ago Up 2 seconds 0.0.0.0:5123->80/tcp mad_hoover
107d8291c6bc 192.168.32.150:5000/zjzc_centos6.5_m1 "bash" 3 hours ago Up 3 hours prickly_colden
99037e5ed32e 192.168.32.150:5000/zjzc_centos6.5_template "bash" 5 hours ago Up 5 hours zjtest02
f63b2633d146 192.168.32.150:5000/zjzc_centos6.5_template "bash" 5 hours ago Up 5 hours zjtest01
docker:/root# docker exec -it d0339cedbb29 bash
zjzc_centos6.5_m2 镜像名字:
bash-4.1# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6 for ServerName
[ OK ]
bash-4.1# netstat -na
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 :::80 :::* LISTEN
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
bash-4.1# curl localhost/scan.html
aaaaaaaaa
bbbbbbbbb
ccccccccc
宿主机上访问:
docker:/root# curl 192.168.32.151:5123/scan.html
aaaaaaaaa
bbbbbbbbb
ccccccccc
转载于:https://www.cnblogs.com/zhaoyangjian724/p/6200293.html