Overview
You run docker compose up and see:
ERROR: network <name> declared as external, but could not be found
This means your Compose file references a network marked as external, but Docker cannot find a pre-existing network with that exact name. Compose does not create external networks for you.
Why it happens
external: truetells Compose to attach to a network that already exists.- If the named network does not exist, you get the error.
- Name mismatches are common. Compose-managed networks are prefixed by the project name (e.g.,
myproj_app_net). If you mark it external without matching the actual name, Compose won’t find it.
Quickstart fix
- List networks and find the exact name you intend to use.
- If missing, create the network.
- Optionally update your Compose file to map the network name correctly.
- Re-run
docker compose up.
Commands
# 1) See existing networks
docker network ls
# 2) Create a user-defined bridge network if needed
docker network create app_net
# 3) Bring the stack up
docker compose up -d
Minimal working example
This example attaches a service to an external network named app_net that you must create beforehand.
version: "3.9"
services:
web:
image: nginx:alpine
ports:
- "8080:80"
networks:
- app
networks:
app:
external: true
name: app_net
Create the network and start the stack:
docker network create app_net
docker compose up -d
If you prefer Compose to manage the network automatically, remove external:
version: "3.9"
services:
web:
image: nginx:alpine
ports:
- "8080:80"
networks:
- app
networks:
app:
driver: bridge
Then run:
docker compose up -d
Compose will create a network named <project>_app (project defaults to the directory name).
Common fixes and when to use them
| Fix | When to use |
|---|---|
Create the network: docker network create <name> | You truly want a pre-existing, shared network. |
Map the external name: external: true + name: actual_name | Your Compose logical name differs from the Docker network name. |
Remove external and let Compose create it | Network is only used by this project and need not be shared. |
Align project name: docker compose -p myproj up | You want to attach to a Compose-created network with a known prefix, e.g., myproj_app. |
Step-by-step diagnosis
- Render the effective config to confirm network names.
docker compose config - Inspect the project name Compose will use (defaults to folder name). Either specify one:
docker compose -p myproj up -d - List networks and look for exact matches.
docker network ls | grep -E "app_net|myproj_app|your_name" - Inspect a candidate network to verify the driver and scope.
docker network inspect app_net - Update your Compose file:
- If using an existing network: ensure
external: trueandname:matchesdocker network ls. - If letting Compose manage it: remove
externaland specifydriverif needed.
- If using an existing network: ensure
Special cases
Compose-generated networks: If another stack created
myproj_app, your file should map to that exact name:networks: app: external: true name: myproj_appOr start with the same project name:
docker compose -p myproj up -dDefault bridge network: Do not mark it external by name
bridge. Instead, prefer a user-defined bridge network for better DNS and isolation. If you must use the default bridge, do not declare it in Compose; services attach implicitly unless you set custom networks.Remote contexts: If using
docker context use remote, the network must exist on that remote. Create it in the active context.Swarm overlay networks: If you reference an overlay network in Compose (non-Swarm), it likely won’t exist. Use a bridge network for local Compose or deploy to Swarm with
docker stack deployand a proper Swarm network.
Pitfalls to avoid
- Name typos or case differences. Docker network names are case-sensitive.
- Assuming Compose auto-creates external networks. It does not.
- Forgetting the project prefix when reusing networks between Compose projects.
- Using environment variable interpolation in network names without verifying the result (
docker compose confighelps). - Mixing contexts or Docker Desktop/WSL2 backends where the network exists in one but not the active context.
Performance notes
- Prefer a single, shared user-defined bridge network for inter-service traffic across multiple Compose projects; it avoids duplicate networks and container reconnect overhead.
- User-defined bridge networks provide built-in DNS-based service discovery and typically perform well for local development.
- Overlay networks (Swarm/Kubernetes) add encryption/encapsulation overhead and are slower than local bridge networks; use only when you need multi-host networking.
- Avoid attaching containers to many networks unnecessarily; each additional network adds connection setup and iptables rules, which can slow container startup.
Tiny FAQ
What does “external network” mean? A network that must already exist in Docker. Compose will not create or delete it.
How do I share a network between multiple Compose projects? Create it once (
docker network create shared_net) and setexternal: truewithname: shared_netin each project.I see
mydir_appindocker network ls. How do I reference it? Map it explicitly:networks: app: external: true name: mydir_appOr run with
docker compose -p mydir up -dto match the prefix.Can I fix this by removing
external: true? Yes, if you don’t need to share the network. Compose will create a project-scoped network automatically.Is it safe to reuse the default
bridgenetwork? It works, but a user-defined bridge is recommended for isolation, naming, and predictability.