Aller au contenu
GuidesConteneursIntermédiaire

Docker Networking Explained for Home Servers

Bridge, host, macvlan and internal Docker networks explained: container DNS, publishing ports, reverse proxy patterns, firewall pitfalls and a troubleshooting checklist.

par HomeServersGuide TeamMis à jour 27 octobre 20264 min de lecture

Why Docker networking confuses everyone

Docker networking is the single biggest source of "why can't my containers talk to each other?" questions. Once you understand a few concepts, it becomes predictable. This guide covers what networks exist, how containers find each other, how to expose services safely and how to debug problems.

New to Docker? Read Docker basics first.

The mental model

Each container gets its own network namespace: its own IP address, its own localhost and its own ports. That last point is the root of many mistakes. Inside a container, localhost means that container, not the host and not another container. To reach another container, you use its service name on a shared network; to reach the host, you use the host's address.

The default bridge vs. user-defined bridges

When you install Docker you get a default bridge network, but you should almost always use a user-defined bridge (Compose creates one automatically per project). The key difference: on a user-defined bridge, containers can reach each other by name through Docker's built-in DNS.

services:
  app:
    image: my/app
    environment:
      - DB_HOST=db
    depends_on: [db]
  db:
    image: postgres:16

Here app connects to the database at the hostname db. No IP addresses are needed, and IPs can change when containers restart anyway.

Publishing ports

Containers are isolated by default. To reach a service from your LAN, publish a port:

    ports:
      - "8080:80"   # host:container

This maps port 8080 on the host to port 80 in the container. Only publish the ports you actually need. Services that only other containers use — databases, caches — should not publish anything.

To limit access to the host itself, bind to localhost:

    ports:
      - "127.0.0.1:8080:80"

Security note: Docker adds its own firewall rules, which can make a published port reachable even if a host firewall like ufw says it is blocked. Bind sensitive ports to 127.0.0.1 or keep them off the host entirely, and see the security checklist.

Host networking

network_mode: host removes network isolation and lets the container share the host's network stack. It is occasionally required (some discovery and media tools, and exporters like node_exporter, need it) but skips Docker's port mapping and reduces isolation, so use it sparingly. There is no ports: section in host mode; the app listens directly on the host.

macvlan: when a container needs a real IP

Sometimes a container must appear as a genuine device on your LAN — the classic case is Pi-hole answering DNS on its own address. A macvlan network gives the container its own MAC address and IP. The main gotcha: the Docker host itself can't talk to the container over macvlan without an extra shim interface. It also generally doesn't work over Wi-Fi. For most setups, publishing port 53 on the host is simpler.

Internal and isolated networks

Create networks with internal: true for containers that should have no internet access, such as a database. Use several networks to separate front-end and back-end:

networks:
  proxy:
  backend:
    internal: true

The web app joins both; the database joins only backend; the reverse proxy joins only proxy.

The clean pattern: one reverse proxy

Instead of publishing a different port for every app, put a reverse proxy in front:

  • Create a shared Docker network (for example proxy).
  • Attach the reverse proxy and each web app to it.
  • The proxy reaches apps by container name; you expose only ports 80/443 to your LAN.
  • Add automatic HTTPS with Caddy or Nginx Proxy Manager.
networks:
  proxy:
    external: true   # created once with: docker network create proxy

This gives you clean hostnames like photos.home.example.com, one place for TLS, and far fewer exposed ports. See the networking guide for DNS and remote access.

Reaching the host from a container

To reach a service running on the Docker host from inside a container, use host.docker.internal. On Linux, add this to the service:

    extra_hosts:
      - "host.docker.internal:host-gateway"

Useful commands

TaskCommand
List networksdocker network ls
Inspect a networkdocker network inspect <name>
See a container's IPsdocker inspect -f '{{json .NetworkSettings.Networks}}' <name>
Test name resolutiondocker exec <name> getent hosts db
Check what listensss -lntp on the host

Quick troubleshooting checklist

  • Containers can't resolve each other? Make sure they're on the same user-defined network, not the default bridge.
  • Port already in use? Something else on the host is bound to it — change the host side of the mapping.
  • Proxy can't reach an app? Confirm both are attached to the shared proxy network and you're using the container name and the container's internal port, not localhost or the published port.
  • Works from the server but not from other devices? Check that the port is published and not bound to 127.0.0.1, and check your router or firewall.
  • Container starts but the app is unreachable? Make sure the app listens on 0.0.0.0 inside the container, not only on 127.0.0.1.

Articles connexes

GuidesConteneursIntermédiaire

Bonnes pratiques Docker Compose pour serveurs domestiques

Structurez stacks, volumes, réseaux et mises à jour pour un homelab Compose maintenable.

5 min de lecture
TutorielsConteneursDébutant

Installer Portainer

Obtenez une interface web pour gérer conteneurs et stacks Docker en quelques minutes.

5 min de lecture
TutorielsConteneursDébutant

Installer Docker sur Ubuntu

Tutoriel pas-à-pas pour installer Docker Engine et Docker Compose sur Ubuntu Server, puis lancer votre premier conteneur.

4 min de lecture