Docker container interconnection
Will be using
docker network to establish a connection, I do not recommend using
--link (if you are already using it, please stop).
Understanding docker network drivers
Docker’s networking subsystem is pluggable, using a specific driver. Understand which driver best suits your purpose based on the below description.
bridge – User-defined bridge networks, best for connecting multiple containers on the same host to communicate.
host – Host networks, best when network stacks not to be isolated from the docker host.
overlay – Overlay networks, best when multiple containers running on different hosts to communicate, or multiple applications works together using docker swarm.
macvlan – Macvlan networks, best when migrating from a VM setup or containers need to look like physical hosts.
- Network plugins – Third-party network plugins allow you to integrate Docker with specialized network stacks.
To understand the container interconnection, follow the example below.
Create a new docker network
Let us create a new docker network by using the code below
-d – Parameter is used to specify the docker network types, as explained above,
macvlan and etc.
Run 2 containers and connect them using the new bridge
Open another terminal and run the below code,
If both the above code was sucessful, try pinging one container from another, like ping
Similarly, you try to ping busybox1 from busybox2 and see if it is reachable.