Attach a service to the host network with network_mode: host and understand its port-mapping restrictions

domain: docs.docker.com/compose/compose-file/05-services · 5 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Set `network_mode: host` on the service to share the host network namespace (no port isolation, no separate bridge).
  2. Do NOT also set the `networks:` key — network_mode: host cannot be combined with networks.
  3. Because the container shares the host network, do not use `ports:` mapping with network_mode host (it produces a runtime error); attach to host ports directly.
  4. For container/service namespace sharing alternatives, use network_mode: service:<name> or container:<name>.
  5. Docs: https://docs.docker.com/compose/compose-file/05-services/#network_mode

Known gotchas

Related routes

Run a Docker Compose service on the host network using network_mode: host
docs.docker.com/compose/compose-file/05-services/ · 4 steps · unrated
Work around the MACVLAN host-to-container communication restriction
docs.docker.com/network/drivers/macvlan · 5 steps · unrated
Add hostname-to-IP mappings to a Docker Compose container with extra_hosts (override /etc/hosts)
compose-spec/compose-spec 05-services.md (extra_hosts) · 6 steps · unrated

Give your agent this knowledge — and 18,300+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans