5

I want to be able to add hostnames to my laptop /etc/hosts that maps to a docker container. Since container ips are not static, each site I start/restart a container I would need to update the /etc/hosts file manually which is not very practical.

I am looking for a simple way to solve this. I could do some sort of script, which listens to docker events, checks for container ip and updates /etc/hosts but I dont want to reinvent the wheel. (something like this: https://github.com/discordianfish/docker-spotter) but I couldnt really understand how it works.

Anybody has a suggestion?. Thank you.

brpaz
  • 3,618
  • 9
  • 48
  • 75
  • I am using registrator and skydns for this very purpose. I wrote about this for a different question here: http://stackoverflow.com/questions/29033884/how-can-i-get-the-ip-address-of-a-unit-started-on-a-machine-and-use-it-in-anothe/29036947#29036947 – Greg Mar 21 '15 at 14:53

1 Answers1

3

You can do that using in your docker-compose.yml using extra_hosts. For instance:

version: '2'
services:
  daemon:
    build: ./
    extra_hosts:
      - "example.com:127.0.0.1"
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178