Table of Contents

Host access from container

By default it is possible to access host services on host external interfaces (not loopback). Host is available under IP address of Docker network, so dynamic mapping is needed (address can change).

/etc/hosts

Docker can automatically generate /etc/hosts to provide name resolution of other containers. This can be extended by:

docker run --add-host=host.docker.internal:host-gateway
docker-compose.yml
    extra_hosts:
      - "host.docker.internal:host-gateway"

List of usefull DNS aliases:

  1. host-gateway
  2. gateway.docker.internal
  3. host.docker.internal - (already exists on Win and MAC, for Linux manual mapping is needed)

NOTE: Supported in Docker version 20.10.0

loopback access

host network mode

Using host network mode exposes host network stack do container!