On Mac and Windows it is possible to use docker.for.mac.host.internal
(replaces docker.for.mac.localhost
) and docker.for.win.host.int
Depends what you're trying to do. If you're running with --net=host
, localhost
should work fine. If you're using default networking, use the static IP 172.17.0.1
. I suspect neither will behave quite the same as those domains.
Using the docker0 interface ip, say 172.17.0.1, could be a good workaround.
Just be sure that the service you need to reach listens to external connections. A typical example is Mysql who binds to 127.0.0.1 by default, resulting unreachable until you allow external connections (es. binding to 0.0.0.0)
One solution is to use a special container which redirects traffic to the host. You can find such a container here: https://github.com/qoomon/docker-host. The idea is to grab the default route from within the container and install that as a NAT gateway for incoming connections.
An imaginary example usage:
docker-host:
image: qoomon/docker-host
cap_add: [ 'NET_ADMIN', 'NET_RAW' ]
restart: on-failure
environment:
- PORTS=999
some-service:
image: ...
environment:
SERVER_URL: "http://docker-host:999"
command: ...
depends_on:
- docker-host