The docker-compose up command failed because the Docker daemon could not locate the network that your services were configured to use.
This error typically means that Docker Compose tried to connect your containers to a network that doesn’t exist or is no longer accessible. The most common culprit is a mismatch between the network name defined in your docker-compose.yml file and what Docker actually has available.
Here’s a breakdown of the common causes and how to fix them:
1. Network Name Typo or Case Sensitivity:
-
Diagnosis: Carefully examine your
docker-compose.ymlfile. Look for thenetworks:section and the network names specified under each service’snetworks:key. Docker network names are case-sensitive. A simple typo likemy_netinstead ofmy_netorMyNetworkinstead ofmynetworkwill cause this. -
Fix: Correct any typos or case discrepancies in your
docker-compose.ymlfile. For instance, if yourdocker-compose.ymlhas:services: web: image: nginx networks: - my_network # <-- potential typo or case issue here networks: my_network: # <-- and hereAnd you intended
my_network, ensure both instances match exactly. -
Why it works: Docker Compose creates networks with specific names. If the name it’s asked to connect to doesn’t exist exactly as specified, it can’t fulfill the request.
2. Network Was Manually Removed:
- Diagnosis: Check if the network was created independently of
docker-compose upand then manually deleted. Rundocker network lsand look for a network name that matches what’s in yourdocker-compose.yml(or a prefixed version likeyourprojectname_my_network). If it’s not listed, it’s gone. - Fix: Run
docker network create your_network_name(replaceyour_network_namewith the name from yourdocker-compose.yml) before runningdocker-compose up. Alternatively, remove theexternal: trueflag from the network definition in yourdocker-compose.ymlif you want Compose to manage its creation and deletion. - Why it works: If you declared a network as
external: truein yourdocker-compose.yml, Compose expects it to exist already. If it doesn’t, the error occurs. Creating it manually or letting Compose manage it resolves this dependency.
3. Network Created by a Different Compose Project:
- Diagnosis: If you’re using the same network name across multiple
docker-compose.ymlfiles, and one project is already running and using that network, a newdocker-compose upmight fail if it tries to recreate or access the network in an incompatible way. Rundocker network inspect your_network_nameto see which containers are attached. - Fix: Either use unique network names for each
docker-compose.ymlfile or ensure that only one project is actively managing the network. If you want Compose to manage it, you might need to stop and remove the other project (docker-compose downin the other project’s directory). - Why it works: Docker networks are generally project-scoped by default when managed by Compose. If a network is declared as external, and another Compose project has already claimed it, conflicts can arise.
4. Docker Daemon Restarted or System Rebooted:
- Diagnosis: If Docker was restarted or the host machine rebooted after you created networks manually or with a previous
docker-compose upcommand, those networks might not have been automatically re-attached or might have been lost if not persisted. Checkdocker network ls. - Fix: Run
docker-compose up -dagain. If the network was declared asexternal: trueand is still missing, you’ll need to recreate it manually usingdocker network create your_network_name. If it’s not external,docker-compose upshould recreate it. - Why it works: Networks created by
docker-compose upare typically tied to the Compose project’s lifecycle. If the daemon restarts, Compose needs to re-establish these connections. Manually created external networks might need manual re-creation if they weren’t properly persisted.
5. Corrupted Docker Network State:
- Diagnosis: In rare cases, the Docker daemon’s internal state regarding networks can become corrupted. This is harder to diagnose directly but often shows up as persistent "network not found" errors even after trying other fixes.
- Fix: The most drastic but effective fix is to prune all unused Docker networks and then try
docker-compose upagain. Rundocker network prune -f. If that doesn’t work, you may need to restart the Docker daemon (sudo systemctl restart dockeron Linux) or, as a last resort, reset Docker entirely (which involves stopping all containers and networks). - Why it works: This cleans up any lingering, inconsistent network configurations within the Docker daemon, forcing it to rebuild its network state from scratch.
6. Incorrect Network Driver Specified (Less Common for "Not Found"):
- Diagnosis: While less likely to cause a direct "network not found" error, if you’ve specified a custom network driver in your
docker-compose.ymland that driver isn’t installed or available on the Docker host, Compose might fail to create or attach to the network. - Fix: Ensure the specified network driver (e.g.,
overlay,macvlan, or a third-party plugin) is correctly installed and configured on your Docker daemon. For standard bridge networks, this is usually not an issue. - Why it works: Docker relies on specific drivers to create and manage network types. If the requested driver is absent, the network cannot be provisioned.
After applying these fixes, run docker-compose up again. If everything is correct, you should see your services starting up.
The next error you’ll likely encounter if you haven’t addressed all configuration issues is a "Service […] is unhealthy" message, indicating that while the container started, the application inside isn’t passing its health checks.