github.com/vincentwoo/docker@v0.7.3-0.20160116130405-82401a4b13c0/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  
    23  Connects a container to a network. You can connect a container by name
    24  or by ID. Once connected, the container can communicate with other containers in
    25  the same network.
    26  
    27  ```bash
    28  $ docker network connect multi-host-network container1
    29  ```
    30  
    31  You can also use the `docker run --net=<network-name>` option to start a container and immediately connect it to a network.
    32  
    33  ```bash
    34  $ docker run -itd --net=multi-host-network busybox
    35  ```
    36  
    37  You can specify the IP address you want to be assigned to the container's interface.
    38  
    39  ```bash
    40  $ docker network connect --ip 10.10.36.122 multi-host-network container2
    41  ```
    42  
    43  You can use `--link` option to link another container with a prefered alias
    44  
    45  ```bash
    46  $ docker network connect --link container1:c1 multi-host-network container2
    47  ```
    48  
    49  `--alias` option can be used to resolve the container by another name in the network
    50  being connected to.
    51  
    52  ```bash
    53  $ docker network connect --alias db --alias mysql multi-host-network container2
    54  ```
    55  
    56  You can pause, restart, and stop containers that are connected to a network.
    57  Paused containers remain connected and can be revealed by a `network inspect`.
    58  When the container is stopped, it does not appear on the network until you restart
    59  it. If specified, the container's IP address(es) will be reapplied (if still available)
    60  when a stopped container rejoins the network. One way to guarantee that the container
    61  will be assigned the same IP addresses when it rejoins the network after a stop
    62  or a disconnect, is to specify the `--ip-range` when creating the network, and choose
    63  the static IP address(es) from outside the range. This will ensure that the IP address
    64  will not be given to other dynamic containers while this container is not on the network.
    65  
    66  ```bash
    67  $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network
    68  ```
    69  
    70  ```bash
    71  $ docker network connect --ip 172.20.128.2 multi-host-network container2
    72  ```
    73  
    74  To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network.
    75  
    76  Once connected in network, containers can communicate using only another
    77  container's IP address or name. For `overlay` networks or custom plugins that
    78  support multi-host connectivity, containers connected to the same multi-host
    79  network but launched from different Engines can also communicate in this way.
    80  
    81  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.
    82  
    83  ## Related information
    84  
    85  * [network inspect](network_inspect.md)
    86  * [network create](network_create.md)
    87  * [network disconnect](network_disconnect.md)
    88  * [network ls](network_ls.md)
    89  * [network rm](network_rm.md)
    90  * [Understand Docker container networks](../../userguide/networking/dockernetworks.md)
    91  * [Work with networks](../../userguide/networking/work-with-networks.md)