Home Ask Login Register

Developers Planet

Your answer is one click away!

hyprstack February 2016

Write to /etc/hosts in docker container when running docker container

I am trying to write to the file in /etc/hosts within a docker container when I perform the run command, but when I shh into the container and check the hosts file, nothing has been written.

What is the correct command to do this?

I am running my image with the following command:

docker run -it -p 3000:3000 <imageName> bash echo mypath.dev >> /etc/hosts


Mark O'Connor February 2016

Use the "add-host" parameter when running the container:

docker run -it --add-host db-static: ubuntu cat /etc/hosts

Sergiu Cornea February 2016

But what's stopping you from copying the hosts file straight from your host to that location?

Post Status

Asked in February 2016
Viewed 2,882 times
Voted 12
Answered 2 times


Leave an answer

Quote of the day: live life