github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/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  # network connect
     8  
     9  ```markdown
    10  Usage:  docker network connect [OPTIONS] NETWORK CONTAINER
    11  
    12  Connect a container to a network
    13  
    14  Options:
    15        --alias value           Add network-scoped alias for the container (default [])
    16        --help                  Print usage
    17        --ip string             IPv4 address (e.g., 172.30.100.104)
    18        --ip6 string            IPv6 address (e.g., 2001:db8::33)
    19        --link value            Add link to another container (default [])
    20        --link-local-ip value   Add a link-local address for the container (default [])
    21  ```
    22  
    23  ## Description
    24  
    25  Connects a container to a network. You can connect a container by name
    26  or by ID. Once connected, the container can communicate with other containers in
    27  the same network.
    28  
    29  ## Examples
    30  
    31  ### Connect a running container to a network
    32  
    33  ```bash
    34  $ docker network connect multi-host-network container1
    35  ```
    36  
    37  ### Connect a container to a network when it starts
    38  
    39  You can also use the `docker run --network=<network-name>` option to start a container and immediately connect it to a network.
    40  
    41  ```bash
    42  $ docker run -itd --network=multi-host-network busybox
    43  ```
    44  
    45  ### Specify the IP address a container will use on a given network
    46  
    47  You can specify the IP address you want to be assigned to the container's interface.
    48  
    49  ```bash
    50  $ docker network connect --ip 10.10.36.122 multi-host-network container2
    51  ```
    52  
    53  ### Use the legacy `--link` option
    54  
    55  You can use `--link` option to link another container with a preferred alias
    56  
    57  ```bash
    58  $ docker network connect --link container1:c1 multi-host-network container2
    59  ```
    60  
    61  ### Create a network alias for a container
    62  
    63  `--alias` option can be used to resolve the container by another name in the network
    64  being connected to.
    65  
    66  ```bash
    67  $ docker network connect --alias db --alias mysql multi-host-network container2
    68  ```
    69  
    70  ### Network implications of stopping, pausing, or restarting containers
    71  
    72  You can pause, restart, and stop containers that are connected to a network.
    73  A container connects to its configured networks when it runs.
    74  
    75  If specified, the container's IP address(es) is reapplied when a stopped
    76  container is restarted. If the IP address is no longer available, the container
    77  fails to start. One way to guarantee that the IP address is available is
    78  to specify an `--ip-range` when creating the network, and choose the static IP
    79  address(es) from outside that range. This ensures that the IP address is not
    80  given to another container while this container is not on the network.
    81  
    82  ```bash
    83  $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network
    84  ```
    85  
    86  ```bash
    87  $ docker network connect --ip 172.20.128.2 multi-host-network container2
    88  ```
    89  
    90  To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network.
    91  
    92  Once connected in network, containers can communicate using only another
    93  container's IP address or name. For `overlay` networks or custom plugins that
    94  support multi-host connectivity, containers connected to the same multi-host
    95  network but launched from different Engines can also communicate in this way.
    96  
    97  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.
    98  
    99  ## Related commands
   100  
   101  * [network inspect](network_inspect.md)
   102  * [network create](network_create.md)
   103  * [network disconnect](network_disconnect.md)
   104  * [network ls](network_ls.md)
   105  * [network rm](network_rm.md)
   106  * [network prune](network_prune.md)
   107  * [Understand Docker container networks](https://docs.docker.com/network/)
   108  * [Work with networks](https://docs.docker.com/network/bridge/)