github.com/vincentwoo/docker@v0.7.3-0.20160116130405-82401a4b13c0/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 28 You can pause, restart, and stop containers that are connected to a network. 29 Paused containers remain connected and can be revealed by a `network inspect`. 30 When the container is stopped, it does not appear on the network until you restart 31 it. If specified, the container's IP address(es) will be reapplied (if still available) 32 when a stopped container rejoins the network. One way to guarantee that the container 33 will be assigned the same IP addresses when it rejoins the network after a stop 34 or a disconnect, is to specify the `--ip-range` when creating the network, and choose 35 the static IP address(es) from outside the range. This will ensure that the IP address 36 will not be given to other dynamic containers while this container is not on the network. 37 38 ```bash 39 $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network 40 ``` 41 42 ```bash 43 $ docker network connect --ip 172.20.128.2 multi-host-network container2 44 ``` 45 46 To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network. 47 48 Once connected in network, containers can communicate using only another 49 container's IP address or name. For `overlay` networks or custom plugins that 50 support multi-host connectivity, containers connected to the same multi-host 51 network but launched from different Engines can also communicate in this way. 52 53 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. 54 55 56 # OPTIONS 57 **NETWORK** 58 Specify network name 59 60 **CONTAINER** 61 Specify container name 62 63 **--help** 64 Print usage statement 65 66 # HISTORY 67 OCT 2015, created by Mary Anthony <mary@docker.com>