Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Networks in Docker

Access local network from Docker container

Section titled “Access local network from Docker container”

You can choose to use the host network instead of the default bridge network in your Docker container. This way, the container will share the network namespace with its host and will have access to the host’s network interfaces.

Run the container with the --network host option:

Terminal window
docker run --network host my-image

Then, the container can access services running on the host using localhost like you would on the host machine itself.

More information on the official Docker documentation.
Official Docker guide on using the host network.

Docker provides a special DNS name host.docker.internal that resolves to the host’s internal IP address. This way, the container can access services exposed on the host.

Then, the container can access services running on the host using host.docker.internal, the same way you would using localhost on the host machine itself.

Official Docker documentation on this hostname.

With Docker Compose, you can set the extra_hosts property to define the host.docker.internal hostname:

services:
my-service:
extra_hosts:
- "host.docker.internal:host-gateway"