Dockerfile:
FROM ubuntu:latest
RUN touch /tmp/foo
RUN echo 'bar' > /tmp/foo
RUN echo '192.168.99.100 foo' >> /etc/hosts
ENTRYPOINT /bin/bash
Inside the container:
root@47040a03cbc1:/# cat /tmp/foo
bar
root@47040a03cbc1:/# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.4 47040a03cbc1
Why does the first echo to /tmp/foo
works but the second to /etc/hosts
doesn't?
Docker manages /etc/hosts. It does this to make container linking work. You can ask docker to append to the hosts file when starting the container with
docker run -it --add-host foo:192.168.99.100
If use docker composer:
extra_hosts:
- "foo:192.168.99.100"
- "bar:192.168.99.101"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With