Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Docker from editing my hosts file?

Tags:

docker

Since a recent Docker update on my Windows machine, Docker Desktop started adding entries to my etc\hosts file. I'm not sure which build introduced it, but I'm currently on Docker Desktop Community 2.1.0.1 (31799).

I want my etc\hosts file to contain only the following entry:

127.0.0.1 localhost host.docker.internal

But every now and then, Docker Desktop adds additional entries resulting in:

127.0.0.1       localhost host.docker.internal
# Added by Docker Desktop
10.4.123.44 host.docker.internal
10.4.123.44 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

If I remove them, they eventually reappear. How do I prevent Docker from adding these entries?

like image 964
Auberon Avatar asked Sep 10 '19 15:09

Auberon


1 Answers

Why do you not want to allow Docker to manage your hosts file? I think you may get some unwanted behaviour if you do.

That said, you can probably just make the file read only.

Right-click > Properties > Check Read Only > Apply

You'll have to update this when making changes but it will also prevent Docker from writing to it.

like image 165
leeman24 Avatar answered Oct 23 '22 03:10

leeman24