Inter container network communications

I’m using compose to start many containers (apache, mysql, slurm, ftpd).
The containers need to talk (IP) to the others.
What is the good solution to achieve that.

  • I could setup the IP’s when running the containers and have hard
    coded config files with those IP’s, looks ugly to me and I think
    don’t fit with Docker philosophy.
  • I could made a script that does
    docker inspect the container after the run and send the configs to
    the vm, i don’t like it too.
  • I could map ports from the Docker host
    to the container internal ports, so all could talk to the Docker host
    IP with those specific ports. (In that case i see in the forum a pending question, how to get the docker host ip in the container)

Which one is the best, or is there another way ?


You can use Docker Links for this

Links help you to communicate between containers without knowing the IP Address. You link containers and address each other container using an alias you define.

Please let me know if this helps.


Since this morning I understood some things.
In the docker-compose yml i can add links, ex :
image: php:5.6-apache
- “80:80”
- "443:443"
- mysql
- ftpd
- slurm

In this container, there are env variable setup that helps finding the other container.
The problem is that the other containers don’t know anything about the others,
In my example web knows about ftpd, but ftpd know nothing about web (nothing is not exact in the /etc/hosts there are the IP’s of all containers), but no env variables like in web.
I tried to link ftps with web but it does nothing :confused:

Using the basic container linking this is not possible as you wont be able to link to a non running container.

In such situations you should have some kind of service discovery solution like SkyDNS ( ). These services registers each containers as they come up with their IP and hostname.

There is a new networking stack that is being developed for Docker ( ) which is available in the experimental builds of docker. There we have the concept of network and services where we have more flexibility in communication between containers.

So for your requirement Service Discovery is the concept you have to explore more on.


1 Like

thank you very much for the hints
i’m digging more :wink: