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
192.168.12.123 host.docker.internal
192.168.12.123 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 127.0.0.1 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?

2 Likes

Developers at my company run into this same issue. We set the host.docker.internal hostname to 127.0.0.1 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: 2.2.0.3 (42716)
Steps to reproduce:

  1. Start Docker Desktop

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

  3. Restart Computer

1 Like

Is there any solution for the able issue?

Got same issue, every time I restart PC (which then starts Docker), it messes up my hosts file.

Afaik, this is controlled by “Add the *.docker.internal names to the host’s /etc/hosts file (Requires password)” in the General section of the settings.