Docker Community Forums

Share and learn in the Docker community.

Edit /etc/hosts in Dockerfile

I need to configure a Dockerfile to edit file /etc/hosts inside docker container.
My Dockerfile is setted to download from image “php:5.6-apache”.

I tried to copy inside my container a sh script that append a configuration line in hosts file,
but when container is started, the hosts file isn’t changed.
Any suggestions?

--add-host could be used

Yeah, I’m not sure if you can set the /etc/hosts in the image as it gets over-written at runtime by Docker. This is needed for some things such as Docker built-in networking.