2

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 192.168.56.101 mypath.dev >> /etc/hosts

5
  • 1
    -it and -d are conflicting. The first spawns an interactive terminal, the second lets it run as a daemon in the background. Please fix that first. Commented Feb 8, 2016 at 11:54
  • ahh, sorry. I had been playing around with it and forgot to remove the -d Commented Feb 8, 2016 at 11:55
  • I'm a bit confused about the first semicolon. I'd start a bash with docker run ... myimage bash (no semicolon here). Commented Feb 8, 2016 at 11:58
  • My problem is not with starting a bash. It's adding the IP address to the hosts file so that I don't have to do it manually everytime. Commented Feb 8, 2016 at 12:06
  • The IP address that you want to include in /etc/hosts is for another container in your docker host? This is not the best ways to connect containers Commented Feb 8, 2016 at 18:48

1 Answer 1

4

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

docker run -it --add-host db-static:86.75.30.9 ubuntu cat /etc/hosts
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.