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