Docker Networking

Docker Networking

 Docker Networking


Docker provides an option to create and manage their own network for networking between docker containers. Use docker network subcommand to manage the Docker networking.

Syntax:

docker network [options]

Use the below tutorial to create, list, and manage Docker networking.

List Docker Networks

Use the ls option with the docker network command to list the currently available network on the docker host.

docker network ls

Create Docker Network

Docker provides multiple types of networks. The below command will create a bridge network on your system.

Syntax:

docker network create -d [network_type] [network_name]

Example:

docker network create -d bridge my-bridge-network

Connect Container to Network

You can connect any container to an existing docker network by using the container's name or ID. Once the container is connected to the network, it can communicate with other containers in the same network.

Syntax:

docker network connect [network_name] [container_name]

Example:

docker network connect my-bridge-network centos

Disconnect Container from Network

You can disconnect a container from the specific network at any time using the following command.

Syntax:

docker network disconnect [network_name] [container_name]

Example:

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.

Example:

docker network rm my-bridge-network network2 network3

You can also remove all unused networks from the docker host using the prune option.

docker network prune
Reactions

Post a Comment

0 Comments

close