github.com/kobeld/docker@v1.12.0-rc1/docs/reference/commandline/network_connect.md (about) 1 <!--[metadata]> 2 +++ 3 title = "network connect" 4 description = "The network connect command description and usage" 5 keywords = ["network, connect, user-defined"] 6 [menu.main] 7 parent = "smn_cli" 8 +++ 9 <![end-metadata]--> 10 11 # network connect 12 13 Usage: docker network connect [OPTIONS] NETWORK CONTAINER 14 15 Connects a container to a network 16 17 --alias=[] Add network-scoped alias for the container 18 --help Print usage 19 --ip IPv4 Address 20 --ip6 IPv6 Address 21 --link=[] Add a link to another container 22 --link-local-ip=[] IPv4/IPv6 link-local addresses 23 24 Connects a container to a network. You can connect a container by name 25 or by ID. Once connected, the container can communicate with other containers in 26 the same network. 27 28 ```bash 29 $ docker network connect multi-host-network container1 30 ``` 31 32 You can also use the `docker run --net=<network-name>` option to start a container and immediately connect it to a network. 33 34 ```bash 35 $ docker run -itd --net=multi-host-network busybox 36 ``` 37 38 You can specify the IP address you want to be assigned to the container's interface. 39 40 ```bash 41 $ docker network connect --ip 10.10.36.122 multi-host-network container2 42 ``` 43 44 You can use `--link` option to link another container with a preferred alias 45 46 ```bash 47 $ docker network connect --link container1:c1 multi-host-network container2 48 ``` 49 50 `--alias` option can be used to resolve the container by another name in the network 51 being connected to. 52 53 ```bash 54 $ docker network connect --alias db --alias mysql multi-host-network container2 55 ``` 56 57 You can pause, restart, and stop containers that are connected to a network. 58 Paused containers remain connected and can be revealed by a `network inspect`. 59 When the container is stopped, it does not appear on the network until you restart 60 it. 61 62 If specified, the container's IP address(es) is reapplied when a stopped 63 container is restarted. If the IP address is no longer available, the container 64 fails to start. One way to guarantee that the IP address is available is 65 to specify an `--ip-range` when creating the network, and choose the static IP 66 address(es) from outside that range. This ensures that the IP address is not 67 given to another container while this container is not on the network. 68 69 ```bash 70 $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network 71 ``` 72 73 ```bash 74 $ docker network connect --ip 172.20.128.2 multi-host-network container2 75 ``` 76 77 To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network. 78 79 Once connected in network, containers can communicate using only another 80 container's IP address or name. For `overlay` networks or custom plugins that 81 support multi-host connectivity, containers connected to the same multi-host 82 network but launched from different Engines can also communicate in this way. 83 84 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. 85 86 ## Related information 87 88 * [network inspect](network_inspect.md) 89 * [network create](network_create.md) 90 * [network disconnect](network_disconnect.md) 91 * [network ls](network_ls.md) 92 * [network rm](network_rm.md) 93 * [Understand Docker container networks](../../userguide/networking/dockernetworks.md) 94 * [Work with networks](../../userguide/networking/work-with-networks.md)