github.com/45cali/docker@v1.11.1/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 preferred 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.
    60  
    61  If specified, the container's IP address(es) is reapplied when a stopped
    62  container is restarted. If the IP address is no longer available, the container
    63  fails to start. One way to guarantee that the IP address is available is
    64  to specify an `--ip-range` when creating the network, and choose the static IP
    65  address(es) from outside that range. This ensures that the IP address is not
    66  given to another container while this container is not on the network.
    67  
    68  ```bash
    69  $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network
    70  ```
    71  
    72  ```bash
    73  $ docker network connect --ip 172.20.128.2 multi-host-network container2
    74  ```
    75  
    76  To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network.
    77  
    78  Once connected in network, containers can communicate using only another
    79  container's IP address or name. For `overlay` networks or custom plugins that
    80  support multi-host connectivity, containers connected to the same multi-host
    81  network but launched from different Engines can also communicate in this way.
    82  
    83  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.
    84  
    85  ## Related information
    86  
    87  * [network inspect](network_inspect.md)
    88  * [network create](network_create.md)
    89  * [network disconnect](network_disconnect.md)
    90  * [network ls](network_ls.md)
    91  * [network rm](network_rm.md)
    92  * [Understand Docker container networks](../../userguide/networking/dockernetworks.md)
    93  * [Work with networks](../../userguide/networking/work-with-networks.md)