Skip to content
Related Articles
Open in App
Not now

Related Articles

Basics of Docker Networking

Improve Article
Save Article
  • Last Updated : 31 Oct, 2020
Improve Article
Save Article

Docker Networking allows you to create a Network of Docker Containers managed by a master node called the manager. Containers inside the Docker Network can talk to each other by sharing packets of information. In this article, we will discuss some basic commands that would help you get started with Docker Networking.

1. Understanding the Docker Network Command

The Docker Network command is the main command that would allow you to create, manage, and configure your Docker Network. Let’s see what are the sub-commands that can be used with the Docker Network command.

sudo docker network

Docker Network Command

We will see all the Network sub-commands one by one.

2. Using Docker Network Create sub-command

The Create sub-command allows you to create a Docker Network. 

sudo docker network create --driver <driver-name> <bridge-name>

Docker Network Create sub-command

3. Using Docker Network Connect sub-command

Using Connect sub-command, you can connect a running Docker Container to an existing Network.

sudo docker network connect <network-name> <container-name or id>

In this example, we will connect an Ubuntu Container to the Bridge Network we created in the last step.

Docker Network Connect sub-command

4. Using Docker Network Inspect sub-command

Using the Network Inspect command, you can find out the details of a Docker Network.

sudo docker network inspect <network-name>

Docker Network Inspect sub-command

You can also find the list of Containers that are connected to the Network.

Docker Network Inspect sub-command

5. Using Docker Network ls sub-command

To list all the Docker Networks, you can use the list sub-command.

sudo docker network ls

 Docker Network ls sub-command

6. Using Docker Network Disconnect sub-command

The disconnect sub-command can be used to remove a Container from the Network.

sudo docker network disconnect <network-name> <container-name>

Docker Network Disconnect sub-command

7. Using Docker Network rm sub-command

You can remove a Docker Network using the rm sub-command.

sudo docker network rm <network-name>

Note that if you want to remove a network, you need to make sure that no container is currently referencing the network.

 Docker Network rm sub-command

8. Using Docker Network prune sub-command

To remove all the unused Docker Networks, you can use the prune sub-command. 

sudo docker network prune

Docker Network prune sub-command

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!