docker容器网络更改

由于粗心大意导致在创建容器时候把网络指定错了 如何在不删除容器的情况下更改容器网络呢

更改网络

###解除容器绑定的网络 网络名词mynetwork 容器名称 lnmp
[root@lnmp tp6cms]# docker network disconnect mynetwork lnmp
##删除原先的网络
[root@lnmp tp6cms]# docker network rm mynetwork
##重新创建容器网络
[root@lnmp tp6cms]# docker network create --subnet=192.168.222.0/24 mynetwork
7d40e0be1fcade91f8109a54a05bf0f012584e0bbb9449bec5335db247efd0be
##为容器重新指定网络
[root@lnmp tp6cms]# docker network connect mynetwork lnmp 
##重新启动容器
[root@lnmp tp6cms]# docker container restart lnmp

查看效果

[root@lnmp tp6cms]# docker exec -it lnmp bash
[root@cfd6a87a948e /]# ip add
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
36: eth0@if37:  mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:c0:a8:de:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.222.2/24 brd 192.168.222.255 scope global eth0
       valid_lft forever preferred_lft forever
[root@cfd6a87a948e /]# ping 10.87.232.171
PING 10.87.232.171 (10.87.232.171) 56(84) bytes of data.
64 bytes from 10.87.232.171: icmp_seq=1 ttl=61 time=0.626 ms
64 bytes from 10.87.232.171: icmp_seq=2 ttl=61 time=0.424 ms
^C
--- 10.87.232.171 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.424/0.525/0.626/0.101 ms
[root@cfd6a87a948e /]# ping 10.87.230.205
PING 10.87.230.205 (10.87.230.205) 56(84) bytes of data.
64 bytes from 10.87.230.205: icmp_seq=1 ttl=63 time=0.580 ms
64 bytes from 10.87.230.205: icmp_seq=2 ttl=63 time=0.265 ms
64 bytes from 10.87.230.205: icmp_seq=3 ttl=63 time=0.224 ms

你可能感兴趣的:(操作系统,docker,linux)