So I usually use my container with network mode set to host, however I decided to use docker network create to create a new network device for the container (it is using default bridge mode). Now i want to add a line into /etc/hosts inside the contianer to block access to a single address, I can edit it and it works, however the line deletes itself the moment I have to kill the docker and restart the container. I even docker commit to a new image to make sure it saves, but it seems it doesn’t. Does the container generate /etc/hosts everytime i load the container? If so, how do I set it so the container will generate the additional line? The line is going to be hostname XXX.XXX.XXX?
Details for the setup
Host: Fedora 34/35 using moby-engine
Container: CentOS 7
If you run
docker container inspect "containername"
that will answer your question Keep this command in mind. It gives you helpful information about the container and how its filesystem was built from different merged folders and mounted files.
Just the relevant parts:
I tried to search for it on Google like I didn’t know anything about it. Actually, I didn’t remember exactly, because I almost never use it. So I searched for “docker add host”.
I could have searched for “docker add hostname” which would have also worked, but I usually try to use shorter words first, because Google smart enough to search for a part of a word.
The result is the docker run documentation, where you can find the
If you want to do it with Docker Compose, your next task is to search for “docker compose add host” and you find “extra_hosts”