In docker we can connect two or more containers or non-docker system using networking. Whether it is a windows or Linux containers, docker network helps to connect them in an easy way. This may helpful for beginners who interested in docker.
There are different network drivers available in docker networking
The default network driver if we don’t mention a network driver when running a container. It is created automatically when a container is created. It is best for standalone containers
If you use the host network mode for a container, that container’s network stack is not isolated from the Docker host, and the container does not get its own IP-address allocated.
For instance, if you run a container which binds to port 80 and you use host networking, the container’s application is available on port 80 on the host’s IP address.
Overlay is mainly used when we want to connect multiple containers to create a swarm service to communicate between them.
Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. The Docker daemon routes traffic to containers by their MAC addresses.
- The other driver is called
none, which is used when we use third party plugins from docker hub.
Bridge networking tutorial
This tutorial explain how a two standalone containers can be connected by bridge network. Here we create two
alpine linux containers namely alpine1 and alphine2, then connect them using bridge.
We can view the network list using the command
docker network ls
You may see different network listed as
none as following image. Any newly created network also listed here.
Next create two alpine containers as alpine 1 and alpine 2 with following command
docker run -dit --name alpine1 alpine docker run -dit --name alpine2 alpine
The two container created as follows
Then inspect the bridge network to view details of the containers connected to it with the following command
docker network inspect bridge
This will display a JSON format of bridge network details. We could see that by default alpine1 and alpine2 has bridge networks with different IP address as
172.17.0.3/16 respectively .
Now connect to the alpine1 container using
docker attach alpine1
Now attach to the container and ping a website say google.com
-c 2 make 2 limit of ping.
Then try to ping the alpine2 container using the IP
172.17.0.3/16 and check they are connected. If it ping correctly then successfully two containers are connected using bridge.
ping -c 2 172.17.0.3/16
For other docker archive -> go.
For network reference of docker -> go.
1,177 total views