What is the Linux equivalent of "host.docker.internal"? [duplicate]

ghz 1years ago ⋅ 2987 views

Question

This question already has answers here :

[From inside of a Docker container, how do I connect to the localhost of the machine?](/questions/24319662/from-inside-of-a-docker-container-how-do-i- connect-to-the-localhost-of-the-mach) (43 answers)

Closed 1 year ago.

On Mac and Windows, it is possible to use host.docker.internal (Docker 18.03+) inside a container.

Is there one for Linux that will work out of the box without passing environment variables or extracting it using various CLI commands?


Answer

For Linux systems, you can – starting from major version 20.04 of the Docker engine – now also communicate with the host via host.docker.internal. This won't work automatically , but you need to provide the following run flag:

--add-host=host.docker.internal:host-gateway

See the answer here: [How to access host port from docker container](https://stackoverflow.com/questions/31324981/how-to-access-host- port-from-docker-container/61424570#61424570)

See also this answer below to add to a docker-compose file - [What is the Linux equivalent of "host.docker.internal"?](https://stackoverflow.com/questions/48546124/what-is- the-linux-equivalent-of-host-docker-internal/67158212#67158212)