Docker provides an option to create and manage there own network for networking between docker containers. Use docker network subcommand to manage the Docker networking.
docker network [options]
Use below tutorial to create, list and manage Docker networking.
List Docker Networks
Use ls option with docker network command to list currently available network on the docker host.
docker network ls
Create Docker Network
Docker provides multiple types of network. Below command will create a bridge network on your system.
docker network create -d [network_type] [network_name]
docker network create -d bridge my-bridge-network
Connect Container to Network
You can connect any container to an existing docker network by using containers name or ID. Once the container connected to the network, it can communicate with other containers in the same network.
docker network connect [network_name] [container_name]
docker network connect my-bridge-network centos
Disconnect Container from Network
You can disconnect a container from the specific network any time using the following command.
docker network disconnect [network_name] [container_name]
docker network disconnect my-bridge-network centos
Inspect a Docker Network
Use inspect option with docker network comment to view the details of docker network
docker network inspect my-bridge-network
You will get the results like below.
Remove a Docker Network
Use rm option to remove any existing unused Docker network. You can specify one or more networks with space separated to remove.
docker network rm my-bridge-network network2 network3
You can also remove all unused networks from docker host using prune option.
docker network prune