Service "web" uses an undefined network "frontend"
Fixes the docker-compose error `Service "web" uses an undefined network "frontend"`. It explains the verified fix from a real resolved case, when it applies, and what to check first. Not for unrelated docker-compose failures or different error text.
Fix Service "web" uses an undefined network "frontend" (docker-compose)
TL;DR
A service references a network that is not declared in the top-level networks: section. Add the network name under top-level networks: (or fix the typo), and the project validates. If the network already exists outside compose, declare it with external: true.
The error, verbatim:
Service "web" uses an undefined network "frontend"Steps
Reproduce the error to see which network is undefined:
docker compose configSuccess check: The error names the exact service and network.
Add the missing declaration at the top level of the compose file:
grep -n -A3 "^networks:" docker-compose.ymlSuccess check: The network name now appears under top-level networks:.
Re-validate and bring the stack up:
docker compose configSuccess check: The parsed file prints with no errors.
When to use
You hit this exact error while using docker-compose. The trigger list below matches your situation.
When NOT to use
If the error text differs, or the failure is in a different tool (e.g. a Docker daemon error when you only need the compose fix), find the skill for that exact error instead.
Tool compatibility
docker-compose v1 and Compose v2. Any OS.
Variant phrasings
Service "xxx" uses an undefined network "xxx"
uses an undefined network
Root cause
A service lists a network under its networks: key, but that network is never declared in the top-level networks: section of the compose file. Compose validates references before creating anything, so one missing declaration blocks the whole project.
Edge cases
- If the network is created outside compose, declare it with external: true instead of a bare name.
- Typos are the most common cause: network names are case-sensitive.
- With multiple -f files, the top-level networks: must exist in the merged result, not just one file.
Where this came from
Resolved from the public discussion at https://stackoverflow.com/questions/52587359 (so:52587359).