github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/man/docker-network-connect.1.md (about) 1 % DOCKER(1) Docker User Manuals 2 % Docker Community 3 % OCT 2015 4 # NAME 5 docker-network-connect - connect a container to a network 6 7 # SYNOPSIS 8 **docker network connect** 9 [**--help**] 10 NETWORK CONTAINER 11 12 # DESCRIPTION 13 14 Connects a container to a network. You can connect a container by name 15 or by ID. Once connected, the container can communicate with other containers in 16 the same network. 17 18 ```bash 19 $ docker network connect multi-host-network container1 20 ``` 21 22 You can also use the `docker run --net=<network-name>` option to start a container and immediately connect it to a network. 23 24 ```bash 25 $ docker run -itd --net=multi-host-network --ip 172.20.88.22 --ip6 2001:db8::8822 busybox 26 ``` 27 You can pause, restart, and stop containers that are connected to a network. 28 A container connects to its configured networks when it runs. 29 30 If specified, the container's IP address(es) is reapplied when a stopped 31 container is restarted. If the IP address is no longer available, the container 32 fails to start. One way to guarantee that the IP address is available is 33 to specify an `--ip-range` when creating the network, and choose the static IP 34 address(es) from outside that range. This ensures that the IP address is not 35 given to another container while this container is not on the network. 36 37 ```bash 38 $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network 39 ``` 40 41 ```bash 42 $ docker network connect --ip 172.20.128.2 multi-host-network container2 43 ``` 44 45 To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network. 46 47 Once connected in network, containers can communicate using only another 48 container's IP address or name. For `overlay` networks or custom plugins that 49 support multi-host connectivity, containers connected to the same multi-host 50 network but launched from different Engines can also communicate in this way. 51 52 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. 53 54 55 # OPTIONS 56 **NETWORK** 57 Specify network name 58 59 **CONTAINER** 60 Specify container name 61 62 **--help** 63 Print usage statement 64 65 # HISTORY 66 OCT 2015, created by Mary Anthony <mary@docker.com>