✦ For everyone, free.

Practical knowledge for real and everyday life

Home

9.2.2.1 Compose Default Network

A focused guide to Compose Default Network, connecting core concepts with practical Docker and container operations.

The Compose default network is the single, automatically created network every service attaches to when a Compose file doesn't declare any networks of its own, providing immediate name-based connectivity between all of an application's services without any explicit network configuration required.

How the Default Network Gets Created

Simply defining services, without any top-level networks key at all, is enough for Compose to create and attach every service to a shared default network automatically.

services:
  api:
    build: .
  db:
    image: postgres:16
docker compose up -d
docker compose exec api ping db

This succeeds without any explicit network configuration in the Compose file, since Compose created this default network and attached both services to it automatically.

How the Default Network Is Named

The default network's actual name is derived from the Compose project's name, typically based on the directory the Compose file resides in, followed by a fixed suffix.

docker network ls
myapp_default

This name reflects both the project (myapp) and the fact that it's the automatically created default network for that project.

Why the Default Network Is Sufficient for Many Applications

For an application where every service genuinely needs to communicate with every other service, the default network's simplicity — requiring no explicit configuration at all — is entirely appropriate and adds no unnecessary complexity.

services:
  frontend:
    depends_on:
      - api
  api:
    depends_on:
      - db
  db:
    image: postgres:16
When the Default Network Alone Isn't Enough

An application needing deliberate network segmentation, isolating certain services from others, requires explicitly declared networks instead of relying solely on this single, shared default.

Why Understanding the Default Network Matters

Recognizing that Compose provides working, name-based service connectivity automatically — without requiring any explicit network declaration — clarifies why many simple Compose files function correctly despite never mentioning networks at all, while also showing the foundation explicit network declarations build upon when more deliberate segmentation is needed.