Docker Community Forums

Share and learn in the Docker community.

Inter container network communications


(Tybreizh29) #1

Hi
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 ?


(Ranjandas) #2

Hi,

You can use Docker Links for this https://docs.docker.com/userguide/dockerlinks/.

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.

Regards


(Tybreizh29) #3

Hi
Since this morning I understood some things.
In the docker-compose yml i can add links, ex :
web:
image: php:5.6-apache
hostname: docker.example.com
ports:
- “80:80”
- "443:443"
links:
- 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:


(Ranjandas) #4

Hi,
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 ( https://github.com/skynetservices/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 ( https://github.com/docker/docker/blob/master/experimental/networking.md ) 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.

Regards


(Tybreizh29) #5

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