.nh .TH "DOCKER" "1" "May 2022" "Docker Community" "Docker User Manuals" .SH NAME .PP docker\-network\-connect \- Connect a container to a network .SH SYNOPSIS .PP \fBdocker network connect [OPTIONS] NETWORK CONTAINER\fP .SH DESCRIPTION .PP Connects a container to a network. You can connect a container by name or by ID. Once connected, the container can communicate with other containers in the same network. .PP .RS .nf $ docker network connect multi\-host\-network container1 .fi .RE .PP You can also use the \fB\fCdocker run \-\-network=\fR option to start a container and immediately connect it to a network. .PP .RS .nf $ docker run \-itd \-\-network=multi\-host\-network \-\-ip 172.20.88.22 \-\-ip6 2001:db8::8822 busybox .fi .RE .PP You can pause, restart, and stop containers that are connected to a network. A container connects to its configured networks when it runs. .PP If specified, the container's IP address(es) is reapplied when a stopped container is restarted. If the IP address is no longer available, the container fails to start. One way to guarantee that the IP address is available is to specify an \fB\fC\-\-ip\-range\fR when creating the network, and choose the static IP address(es) from outside that range. This ensures that the IP address is not given to another container while this container is not on the network. .PP .RS .nf $ docker network create \-\-subnet 172.20.0.0/16 \-\-ip\-range 172.20.240.0/20 multi\-host\-network .fi .RE .PP .RS .nf $ docker network connect \-\-ip 172.20.128.2 multi\-host\-network container2 .fi .RE .PP To verify the container is connected, use the \fB\fCdocker network inspect\fR command. Use \fB\fCdocker network disconnect\fR to remove a container from the network. .PP Once connected in network, containers can communicate using only another container's IP address or name. For \fB\fCoverlay\fR networks or custom plugins that support multi\-host connectivity, containers connected to the same multi\-host network but launched from different Engines can also communicate in this way. .PP 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. .SH OPTIONS .PP \fB\-\-alias\fP=[] Add network\-scoped alias for the container .PP \fB\-\-driver\-opt\fP=[] driver options for the network .PP \fB\-h\fP, \fB\-\-help\fP[=false] help for connect .PP \fB\-\-ip\fP="" IPv4 address (e.g., 172.30.100.104) .PP \fB\-\-ip6\fP="" IPv6 address (e.g., 2001:db8::33) .PP \fB\-\-link\fP= Add link to another container .PP \fB\-\-link\-local\-ip\fP=[] Add a link\-local address for the container .SH SEE ALSO .PP \fBdocker\-network(1)\fP