Docker Community Forums

Share and learn in the Docker community.

Network_mode bridge vs host acting differently with "host.docker.internal"

if I want to communicate by “host.docker.internal” from the Docker container to the Docker host, then this only works with network_mode = “host”.
network_mode = “bridge” does not work.
How can communicate with the Docker host network_mode = “bridge” is active?

Edit: If you are using Docker-for-mac or Docker-for-Windows 18.03+, just connect to your mysql service using the host host.docker.internal (instead of the 127.0.0.1 in your connection string).

As of Docker 18.09.3, this does not work on Docker-for-Linux. A fix has been submitted on March the 8th, 2019 and will hopefully be merged to the code base. Until then, a workaround is to use a container as described in qoomon’s answer.

2020-01: some progress has been made. If all goes well, this should land in Docker 20.04

TLDR
Use --network=“host” in your docker run c