github.com/go/docker@v1.12.0-rc2/man/docker-network-connect.1.md (about)

     1  % DOCKER(1) Docker User Manuals
     2  % Docker Community
     3  % OCT 2015
     4  # NAME
     5  docker-network-connect - connect a container to a network
     6  
     7  # SYNOPSIS
     8  **docker network connect**
     9  [**--help**]
    10  NETWORK CONTAINER
    11  
    12  # DESCRIPTION
    13  
    14  Connects a container to a network. You can connect a container by name
    15  or by ID. Once connected, the container can communicate with other containers in
    16  the same network.
    17  
    18  ```bash
    19  $ docker network connect multi-host-network container1
    20  ```
    21  
    22  You can also use the `docker run --net=<network-name>` option to start a container and immediately connect it to a network.
    23  
    24  ```bash
    25  $ docker run -itd --net=multi-host-network --ip 172.20.88.22 --ip6 2001:db8::8822 busybox
    26  ```
    27  
    28  You can pause, restart, and stop containers that are connected to a network.
    29  Paused containers remain connected and can be revealed by a `network inspect`.
    30  When the container is stopped, it does not appear on the network until you restart
    31  it.
    32  
    33  If specified, the container's IP address(es) is reapplied when a stopped
    34  container is restarted. If the IP address is no longer available, the container
    35  fails to start. One way to guarantee that the IP address is available is
    36  to specify an `--ip-range` when creating the network, and choose the static IP
    37  address(es) from outside that range. This ensures that the IP address is not
    38  given to another container while this container is not on the network.
    39  
    40  ```bash
    41  $ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network
    42  ```
    43  
    44  ```bash
    45  $ docker network connect --ip 172.20.128.2 multi-host-network container2
    46  ```
    47  
    48  To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network.
    49  
    50  Once connected in network, containers can communicate using only another
    51  container's IP address or name. For `overlay` networks or custom plugins that
    52  support multi-host connectivity, containers connected to the same multi-host
    53  network but launched from different Engines can also communicate in this way.
    54  
    55  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.
    56  
    57  
    58  # OPTIONS
    59  **NETWORK**
    60    Specify network name
    61  
    62  **CONTAINER**
    63    Specify container name
    64  
    65  **--help**
    66    Print usage statement
    67  
    68  # HISTORY
    69  OCT 2015, created by Mary Anthony <mary@docker.com>