How to add container domain names to the Docker Host /etc/hosts file

Today I had a case where I was trying to access a container running Jenkins-CI server from the Docker Host.

X11 is installed on the Docker Host, and to access the Jenkins container I had to enter the IP address

I asked Firefox to save the login details to the Jenkins instance running in that container.

This works fine until the IP address of the container gets changed, like when I stopped and started the Jenkins container.

On restart the IP address had changed to something else, like

So Firefox thought this was a different website, and did not populate the password field for me to login to Jenkins-CI as admin.

Looking at the saved passwords in Firefox, I can see the password saved under the first IP address for the running container.

Saving the password again just repeats the password for the next IP address the container has been given.

Is there any way for the Docker Host to save the IP addresses and domain names for all the containers that are running on that host in it’s own /etc/hosts file please, so we can get access to those containers running on that host by domain name, and will not be affected by the IP addresses changing when containers running on that host get their IP addresses changed please?

Possibly in a similar way that the container /etc/hosts files are updated after a container they link to has been stopped and started, and the IP address has changed?

Hope that makes good sense.



Did you run your container with the -p option? You should, and then refer to the host’s IP address.

docker run -d -p 12345:8080 me/jenkins

You can pick any port number you want (including the same port as inside the container, 8080) instead of 12345 here.

If you want to access the service from another system, use your physical host’s IP address or DNS name in the URL. If you want to make the service inaccessible from the network at large, -p

(If you are running with Docker Machine, the IP address will be different; the Docker Toolbox VirtualBox setup usually uses in the final URL.)