How to access host port from docker container

To have a docker container connect to a port on the host machine, you need to use the IP of the docker bridge. Note that localhost will not work from within a docker container. That localhost (or 127.0.0.1) is the localhost of the container.

The shared localhost port is accessible via docker0. It’s usually 172.17.0.1.

You can find it with this command:

ip addr show docker0 | grep -Po 'inet \K[\d.]+'
end of storey Last modified: