github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/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  
    65  You can pause, restart, and stop containers that are connected to a network.
    66  Paused containers remain connected and can be revealed by a `network inspect`.
    67  When the container is stopped, it does not appear on the network until you restart
    68  it.
    69  
    70  If specified, the container's IP address(es) is reapplied when a stopped
    71  container is restarted. If the IP address is no longer available, the container
    72  fails to start. One way to guarantee that the IP address is available is
    73  to specify an `--ip-range` when creating the network, and choose the static IP
    74  address(es) from outside that range. This ensures that the IP address is not
    75  given to another container while this container is not on the network.
    76  
    77  ```bash
    78  $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network
    79  ```
    80  
    81  ```bash
    82  $ docker network connect --ip 172.20.128.2 multi-host-network container2
    83  ```
    84  
    85  To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network.
    86  
    87  Once connected in network, containers can communicate using only another
    88  container's IP address or name. For `overlay` networks or custom plugins that
    89  support multi-host connectivity, containers connected to the same multi-host
    90  network but launched from different Engines can also communicate in this way.
    91  
    92  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.
    93  
    94  ## Related information
    95  
    96  * [network inspect](network_inspect.md)
    97  * [network create](network_create.md)
    98  * [network disconnect](network_disconnect.md)
    99  * [network ls](network_ls.md)
   100  * [network rm](network_rm.md)
   101  * [network prune](network_prune.md)
   102  * [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/)
   103  * [Work with networks](https://docs.docker.com/engine/userguide/networking/work-with-networks/)