I want to update my /etc/hosts
file during "docker build".
I added below line in Dockerfile but it's neither updating /etc/hosts
file nor giving any error.
RUN echo "192.168.33.11 mynginx" >> /etc/hosts
I need to update /etc/hosts
. Can anyone suggest on this?
With a more recent version of docker, this could be done with docker-compose and its
extra_hosts
directiveIn short: modify
/etc/hosts
of your container when running it, not building it.Following worked for me by mounting the file during docker run instead of docker build
Just a quick answer to run your container using:
once the container is open:
then
and then you can
or:
or any editor you like and open it in vim, here you can modify say your startup ip to 0.0.0.0
Since this still comes up as a first answer in Google I'll contribute possible solution.
Command taken from here suprisingly worked for me (Docker 1.13.1, Ubuntu 16.04) :
I think docker recently added the
--add-host
flag to docker build which is really great.[Edit] So this feature was updated on 17.04.0-ce
For more detail on how to use
docker build
with the--add-host
flag please visit: https://docs.docker.com/edge/engine/reference/commandline/build/You can not modify the host file in the image using
echo
inRUN
step because docker daemon will maintain the file(/etc/hosts) and its content(hosts entry) when you start a container from the image.However following can be used to achieve the same:
Key to notice here is the use of
exec
command as docker documentation suggests. Use of exec will make the java command as PID 1 for the container. Docker interrupts will only respond to that.See https://docs.docker.com/engine/reference/builder/#entrypoint