Search code examples
dockerhostsdocker-compose

Using --add-host or extra_hosts with docker-compose


I am using docker-compose to run a test environment, that consists of about 5 different containers. The inter-container links and the shared volumes (volumes-from) works wonderfully. I also expose some ports up to the host machine, which works nicely.

What I am missing is a way to link some of my real servers into this environment, without hardcoding ip address. With docker run, you could use --add-host to add another line in your /etc/hosts file. Is there any way to do something similar with docker-compose?


Solution

  • This works still docker-compose 1.3 with extra_hosts parameter:

    rng:
      build: rng
      extra_hosts:
        seed: 1.2.3.4
        tree: 4.3.2.1