Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/etc/hosts file of a docker container gets overwritten

I create a docker container from a centOS 6.5 image. I make some changes to the /etc/hosts file. I then commit the container, and start the new image in a new container, and the /etc/hosts file gets overwritten. Is there a way of keeping the /etc/hosts file as it is?

like image 972
user1016313 Avatar asked Dec 17 '14 08:12

user1016313


1 Answers

No. See discussion here.

Docker does different things with /etc/hosts depending on what option you give to --net. In the default (bridged) mode, it writes an entry for the hostname and IP address of the container itself. There is no option where it leaves /etc/hosts as in the source image.

Your options include:

  • have your container modify /etc/hosts at startup, before running the real program
  • add entries to /etc/hosts when you run the container with the --add-host option.
like image 160
Bryan Avatar answered Nov 01 '22 23:11

Bryan