I'm having trouble trying to add a default host to a docker image. I have my simple file Dockerfile
with this:
FROM alpine
RUN echo "172.17.0.1 test.docker" >> /etc/hosts
I build the image by running
docker build -t example -f Dockerfile .
Running the container and checking the /etc/hosts file never finds the host that I added when I built the image. I tried using another OS other than Alpine and still get the same thing. Why is this happening and how can I achieve it?
Docker will not allow you to do that because it is a system file, to do what you want use the option --add-host="test.docker:172.17.0.1"
which is part of the network options when launching the container
for more information see https://docs.docker.com/engine/reference/run/#network-settings
I hope it helps, regards