github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/man/src/network/connect.md (about) 1 Connects a container to a network. You can connect a container by name 2 or by ID. Once connected, the container can communicate with other containers in 3 the same network. 4 5 ```bash 6 $ docker network connect multi-host-network container1 7 ``` 8 9 You can also use the `docker run --network=<network-name>` option to start a container and immediately connect it to a network. 10 11 ```bash 12 $ docker run -itd --network=multi-host-network --ip 172.20.88.22 --ip6 2001:db8::8822 busybox 13 ``` 14 You can pause, restart, and stop containers that are connected to a network. 15 A container connects to its configured networks when it runs. 16 17 If specified, the container's IP address(es) is reapplied when a stopped 18 container is restarted. If the IP address is no longer available, the container 19 fails to start. One way to guarantee that the IP address is available is 20 to specify an `--ip-range` when creating the network, and choose the static IP 21 address(es) from outside that range. This ensures that the IP address is not 22 given to another container while this container is not on the network. 23 24 ```bash 25 $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network 26 ``` 27 28 ```bash 29 $ docker network connect --ip 172.20.128.2 multi-host-network container2 30 ``` 31 32 To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network. 33 34 Once connected in network, containers can communicate using only another 35 container's IP address or name. For `overlay` networks or custom plugins that 36 support multi-host connectivity, containers connected to the same multi-host 37 network but launched from different Engines can also communicate in this way. 38 39 You can connect a container to one or more networks. The networks need not be the same type. For example, you can connect a single container bridge and overlay networks.