How to link containers in docker?

Linking is a legacy feature. Please use “user defined networks”:

sudo docker network create mynetwork

Then rerun your containers using this network:

sudo docker run --name rabbitmq -p 8080:80 -d --network mynetwork rabbitmq

Do the same for other containers that you want connected with each other.

Using “user defined networks”, you have an “internal name resolution” at your disposal (somewhat like domain name resolution when visiting websites). You can use the names of the container that you want to refer to, in order to resolve the IP addresses of containers, as long as they are running on the same “user defined network”. With this, you can resolve the IP address of the rabbitmq container with its name, within other containers, on the same network.

All containters on the same “user defined network” will have network connectivity. There is no need for “legacy linking”.

Leave a Comment