docker / docker/cli

[RFD] add configuration option to add `host.docker.internal` by default

Open
#2,290 16 comments 71 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/networking kind/feature platform/desktop
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Pull request https://github.com/moby/moby/pull/40007 implemented a "magic" host-gateway value to allow users to add host.docker.internal to /etc/hosts in containers, mapping it to the gateway IP address (the IP address itself can be configured in the daemon configuration).

With this feature, users running dockerd on Linux can get parity with Docker for Mac / Docker for Windows to have host.docker.internal resolve inside containers.

Currently, this option is "opt-in" on Linux; containers will not be able to resolve host.docker.internal unless they are created with --add-host host.docker.internal:host-gateway

Proposal

Users may want to have the host.docker.internal host added automatically for every container created (similar to how it's currently added automatically on Docker Desktop (Docker for Mac / Docker for Windows).

I suggest to:

  • add an option to the CLI configuration file (~/.docker/config.json) that allows configuring a default (set of) custom hosts for new containers
  • possibly (t.b.d.) an environment variable to configure this

The configuration option could potentially be used by the Docker Desktop team, as a replacement for the current (proprietary) implementation; doing so would make the implementation on Linux and Docker Desktop identical (which would make it less confusing).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Docker CLI configuration at ~/.docker/config.json and tracing how --add-host host.docker.internal:host-gateway is passed when containers are created. Clarify the proposed default custom-host format, its interaction with Docker Desktop, and whether an environment variable is required; done means an agreed design and corresponding implementation scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.