What is Docker Networking?
Docker Networking is one of the most powerful concepts supported by Docker. It’s one of the reasons that Docker Containers communicate with each other and also with Docker Host.
Listing all Docker Networks:
To list all networks, we use the following command:
$ docker network ls
Types of Network Drivers:
The following are the types of Network Drivers:
Bridge Network: It is the basic docker network driver in docker, i.e. if you don’t specify any network driver, then it will run in the bridge network by default. The docker daemon creates virtual ethernet bridge docker0, that automatically forwards the packages between any other attached network interfaces.
Types of Bridge Network:
Default bridge network
From the following steps you can set up a default bridge network:
Step 1: You have to run a container.
To run the container we can use the following command.
$ docker run -itd --name alpine1 alpine
Step 2: Check whether the container is running or not
The following command will check if the container is running or not. If this command’s output is blank, then the container is not running.
$ docker ps
Step 3: Check the network specification of the running container
The following command will tell you about the network specification of the container:
$ docker inspect network <network ID>
Step 4: Run another container by the same image and it will, by default, take the same network.
The commands below will show you that the new container we are launching will automatically run inside the same network that we created above.
For running and checking container running status, commands are:
$ docker run -itd --name alpine2 alpine
$ docker ps
For checking and confirming both the containers are in the same network,
$ docker inspect network <network id>
Step 5: For more confirmation you can ping one container from another using its IP.
Using the commands below, you can check whether containers are communicating with each other. If they are on the same network then they’re successfully messaging each other.
You can go inside the container using the following command:
$ docker exec -it <container id> sh
After going inside the container we are running ping command with the IP of another container.
User-defined bridge network:
Steps to perform bridge networking with a user-defined bridge network are as follows:
Step 1: First of all, create a custom network ‘
Using the following command, you can create your custom network:
$ docker network create <name of network>
You can verify your network by the following command:
$ docker network ls
Step 2: Run containers on your created network
Run the containers inside the network that you have created using the following command:
$ docker run -itd --name alpine3 --network test alpine
Here, the custom network name is test.
Step 3: Verify the container running on your created network
You can verify the container is running on your network by the following command.
$ docker network inspect <network id>
Step 4: Now you can Perform the ping command
To perform ping command we have to execute the shell of the container. We can do this following command,
$ docker exec -it <container id> sh
.
We are an ERP Development Company that uses Docker networking to automate controlling traffic between containers on the network. Use Docker to create and deploy applications with Oodles’ custom software development services. Get in touch with our experts now!