Bootstrap FreeKB - Docker - Append entries to the /etc/hosts file in a container using the docker run --add-host command
Docker - Append entries to the /etc/hosts file in a container using the docker run --add-host command

Updated:   |  Docker articles

When creating a container using the docker run command, the --add-host command can be used to append entries to the /etc/hosts file in the container. In this example, 172.16.0.2 foo.example.com will be appended to /etc/hosts.

docker run --detach --add-host foo.example.com:172.16.0.2 foo:latest

 

After the container has been created and is up and running, the docker exec command can be used to examine the /etc/hosts file in the container.

~]# docker exec foo cat /etc/hosts
127.0.0.1   localhost
::1         localhost ip6-localhost ip6-loopback
fe00::0     ip6-localnet
ff00::0     ip6-mcastprefix
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters
172.16.0.2  foo.example.com

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 1b905f in the box below so that we can be sure you are a human.