Basics of Docker Networking
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
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>
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.
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>
You can also find the list of Containers that are connected to the Network.
5. Using Docker Network ls sub-command
To list all the Docker Networks, you can use the list sub-command.
sudo docker network ls
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>
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.
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
Please Login to comment...