github.com/olljanat/moby@v1.13.1/docs/reference/commandline/network_connect.md (about)

     1  ---
     2  title: "network connect"
     3  description: "The network connect command description and usage"
     4  keywords: "network, connect, user-defined"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/docker Github
     8       repository at https://github.com/docker/docker/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # network connect
    17  
    18  ```markdown
    19  Usage:  docker network connect [OPTIONS] NETWORK CONTAINER
    20  
    21  Connect a container to a network
    22  
    23  Options:
    24        --alias value           Add network-scoped alias for the container (default [])
    25        --help                  Print usage
    26        --ip string             IP Address
    27        --ip6 string            IPv6 Address
    28        --link value            Add link to another container (default [])
    29        --link-local-ip value   Add a link-local address for the container (default [])
    30  ```
    31  
    32  Connects a container to a network. You can connect a container by name
    33  or by ID. Once connected, the container can communicate with other containers in
    34  the same network.
    35  
    36  ```bash
    37  $ docker network connect multi-host-network container1
    38  ```
    39  
    40  You can also use the `docker run --network=<network-name>` option to start a container and immediately connect it to a network.
    41  
    42  ```bash
    43  $ docker run -itd --network=multi-host-network busybox
    44  ```
    45  
    46  You can specify the IP address you want to be assigned to the container's interface.
    47  
    48  ```bash
    49  $ docker network connect --ip 10.10.36.122 multi-host-network container2
    50  ```
    51  
    52  You can use `--link` option to link another container with a preferred alias
    53  
    54  ```bash
    55  $ docker network connect --link container1:c1 multi-host-network container2
    56  ```
    57  
    58  `--alias` option can be used to resolve the container by another name in the network
    59  being connected to.
    60  
    61  ```bash
    62  $ docker network connect --alias db --alias mysql multi-host-network container2
    63  ```
    64  You can pause, restart, and stop containers that are connected to a network.
    65  A container connects to its configured networks when it runs.
    66  
    67  If specified, the container's IP address(es) is reapplied when a stopped
    68  container is restarted. If the IP address is no longer available, the container
    69  fails to start. One way to guarantee that the IP address is available is
    70  to specify an `--ip-range` when creating the network, and choose the static IP
    71  address(es) from outside that range. This ensures that the IP address is not
    72  given to another container while this container is not on the network.
    73  
    74  ```bash
    75  $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network
    76  ```
    77  
    78  ```bash
    79  $ docker network connect --ip 172.20.128.2 multi-host-network container2
    80  ```
    81  
    82  To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network.
    83  
    84  Once connected in network, containers can communicate using only another
    85  container's IP address or name. For `overlay` networks or custom plugins that
    86  support multi-host connectivity, containers connected to the same multi-host
    87  network but launched from different Engines can also communicate in this way.
    88  
    89  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.
    90  
    91  ## Related information
    92  
    93  * [network inspect](network_inspect.md)
    94  * [network create](network_create.md)
    95  * [network disconnect](network_disconnect.md)
    96  * [network ls](network_ls.md)
    97  * [network rm](network_rm.md)
    98  * [network prune](network_prune.md)
    99  * [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/)
   100  * [Work with networks](https://docs.docker.com/engine/userguide/networking/work-with-networks/)