Jack M.
Jack M.

Reputation: 32080

Add to container's /etc/hosts using Fig?

I'm trying to configure fig so that I can connect to my database server without specifying a fully qualified domain name. The database is running on bare metal (not in docker). On the host, glinda.local is specified in /etc/hosts and I'd like the container to mimic this behavior (though not rely on the host's config).

I found this suggestion on github, but it fails since /etc/hosts is on a read-only file system.

So the question remains, how can I add glinda.local from fig.yml to /etc/hosts inside my docker container?

Upvotes: 2

Views: 473

Answers (2)

Javier Cortejoso
Javier Cortejoso

Reputation: 9176

From Docker v1.3.1 (I think) you have available the option --add-host in docker run. Unfortunately this options has not been merged to fig:master yet, but there is a PR with it. When merged (or using that branch) you should be able to use it in this way:

extra_hosts

Add hostname mappings. Use the same values as the docker client --add-hosts parameter.

> extra_hosts:
>  - docker: 162.242.195.82
>  - fig: 50.31.209.229

An entry with the ip address and hostname will be created in /etc/hosts inside containers for this service, e.g:

> 162.242.195.82  docker
> 50.31.209.229   fig

Upvotes: 2

Adrian Mouat
Adrian Mouat

Reputation: 46548

What makes you think /etc/hosts is read-only? The following works for me with Docker 1.5:

$ docker run -it debian
root@0989fd55e8fa:/# echo "127.0.0.1 test" >> /etc/hosts
root@0989fd55e8fa:/# ping test
PING test (127.0.0.1): 48 data bytes
56 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.078 ms
56 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.068 ms
^C--- test ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.068/0.073/0.078/0.000 ms

Are you saying this doesn't work for you? If the above works, you should be able to add what you need into an entrypoint script.

Upvotes: 0

Related Questions