Docker Community Forums

Share and learn in the Docker community.

How to prevent DDfW from changing my hosts file

Docker Desktop keeps adding my network address to my hosts file regardless of what is already in there:

# Added by Docker Desktop host.docker.internal gateway.docker.internal

This is a real problem for me because when I go from my home network to my office network I end up with two sets of conflicting mappings for these names and then these names fail to resolve causing calls to local endpoints to fail. I already have host.docker.internal mapped to and want to keep it that way.

You should be able to turn this behavior off or at the very least be prompted when DD is making these changes.

Is there any way to prevent this behavior other than revoking DD permissions on the file?


Developers at my company run into this same issue. We set the host.docker.internal hostname to to get around this, but these “Added by Docker Desktop” host entries keep getting added back into the hosts file and cause DNS resolution issues. Our Windows users see this issue the most. I would ask that users have a settings option that we can use to disable this

Additional info:
OS Version/Build: Windows 10 Enterprise 1909, 18363.657
Docker Desktop version: (42716)
Steps to reproduce:

  1. Start Docker Desktop

  2. Edit %system%\drivers\etc\hosts file to use for the host.docker.internal hostname and remove the other automatically added entries. Save the changes

  3. Restart Computer