Docker容器重启后IP更改问题处理方法

 

 

启动一个容器cct3

root@ubuntu:~# docker run -it --name cct3--link=cct1:webtest cct

root@eb0cc6e0847f:/# ping webtest

PING webtest (192.168.100.29) 56(84) bytes of data.

64 bytes from webtest (192.168.100.29): icmp_seq=1ttl=64 time=0.070 ms

root@eb0cc6e0847f:/#env

.....

PWD=/

WEBTEST_PORT_80_TCP=tcp://192.168.100.29:80

WEBTEST_PORT=tcp://192.168.100.29:80

WEBTEST_PORT_80_TCP_PROTO=tcp

SHLVL=1

HOME=/root

WEBTEST_PORT_80_TCP_PORT=80

_=/usr/bin/env

root@eb0cc6e0847f:/#

root@eb0cc6e0847f:/#cat /etc/hosts

192.168.100.30       eb0cc6e0847f

127.0.0.1 localhost

::1    localhostip6-localhost ip6-loopback

fe00::0     ip6-localnet

ff00::0     ip6-mcastprefix

ff02::1     ip6-allnodes

ff02::2     ip6-allrouters

192.168.100.29       webtest 5089ac64e262 cct1

root@eb0cc6e0847f:/#

说明:

       1)启动一个容器cct3

       2)容器启动增加了--link=cct1:webtest,连接容器cct1,并起了一个别名;

       3)同时对env和/etc/hosts都有影响;

 

 

重启docker服务

root@eb0cc6e0847f:/# root@ubuntu:~#

root@ubuntu:~#service docker restart

root@ubuntu:~# docker ps

CONTAINER ID       IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 

 

重启容器cct1 cct2cct3

root@ubuntu:~# docker restart cct1 cct2 cct3

 

 

 

进入容器3

root@ubuntu:~# docker attach cct3

root@eb0cc6e0847f:/# ping webtest

PING webtest (192.168.100.2) 56(84) bytes of data.

64 bytes from webtest (192.168.100.2): icmp_seq=1ttl=64 time=0.073 ms

说明:

       1)依旧可以ping通容器cct1;

 

 

查看容器cct3重启后的环境变化

root@eb0cc6e0847f:/# cat /etc/hosts

192.168.100.4         eb0cc6e0847f

127.0.0.1 localhost

::1    localhostip6-localhost ip6-loopback

fe00::0     ip6-localnet

ff00::0     ip6-mcastprefix

ff02::1     ip6-allnodes

ff02::2     ip6-allrouters

192.168.100.2         webtest5089ac64e262 cct1

root@eb0cc6e0847f:/#

root@eb0cc6e0847f:/# env

HOSTNAME=eb0cc6e0847f

 

WEBTEST_PORT_80_TCP=tcp://192.168.100.2:80

WEBTEST_PORT=tcp://192.168.100.2:80

WEBTEST_PORT_80_TCP_PROTO=tcp

SHLVL=1

HOME=/root

WEBTEST_PORT_80_TCP_PORT=80

_=/usr/bin/env

root@eb0cc6e0847f:/#

 

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐