6

I'm new to docker. I got latest docker (18.06.1-ce-win73 (19507)) and this version will somehow modify the hosts file and my company security team block anyone from modify the file. When we request to grant permission but they need to understand why the Docker modify Hosts file.

So could anyone explain why its modify file during startup?

Thanks

enter image description here

tsohtan
  • 830
  • 1
  • 13
  • 33

1 Answers1

1

i'm new with docker too. But, reading this post (How to update /etc/hosts file in Docker image during "docker build") I understand you can update your /etc/hosts file during "docker build".

With a more recent version of docker, this could be done with docker-compose and its extra hosts directive (your version is here)

Add hostname mappings. Use the same values as the docker run client --add-host parameter (which should already be available for docker 1.8).

extra_hosts:
 - "somehost:162.242.195.82"
 - "otherhost:50.31.209.229"

In short: modify /etc/hosts of your container when running it, not building it.

  • 1
    This is correct - just to elaborate on this, Docker is using the hosts file to add network connections to other containers so you can reference them by the ID or name, which is why the file is being edited by Docker. – Neekoy Sep 04 '18 at 12:54
  • Sorry, just now i saw how i not answer yout question. – Lucas Eduardo Scrini Sep 04 '18 at 13:16
  • you did answer the question - I was elaborated a little bit on it. I upvoted your answer because it's correct :) – Neekoy Sep 04 '18 at 13:34
  • This answer is absolutely unrelated to the question: the question is about why is Docker Desktop for Windows updating Windows’ host file, while this answer is about changing the hosts file inside a container. – Didier L Jul 18 '22 at 13:45