How to fix ERROR: Network mynetwork declared as external, but could not be found in Docker

DockerBEGINNERLOWUpdated Dec 1, 2025ยท 193 views

This error occurs when Docker Compose tries to connect a service to an external network that doesn't exist. External networks must be created manually using 'docker network create' before running docker-compose, or you can remove the external flag to let Compose create the network automatically.

Quick fix

Fixes ERROR: Network mynetwork declared as external, but could not be found

# Create a basic bridge network
docker network create mynetwork

# Verify it was created
docker network ls | grep mynetwork
  1. Create the missing network manually
  2. Verify the network name matches your Compose file
  3. Remove external flag if you don't need a shared network
  4. Check for network naming convention issues
docker โ€” error
# Create a basic bridge network
docker network create mynetwork
# Verify it was created
docker network ls | grep mynetwork
ERROR: Network mynetwork declared as external, but could not be found

What this error means

When you declare a network as `external: true` in your `docker-compose.yml` file, you're telling Docker Compose that this network already exists and was created outside of the current Compose project. Docker Compose will not attempt to create it - instead, it expects to find an existing network with that name. The "declared as external, but could not be found" error means Docker Compose queried the Docker daemon for a network with the specified name and didn't find one. This commonly happens when: - You're setting up a project for the first time and forgot to create the network - The network was deleted or never existed - There's a mismatch between the network name in your Compose file and the actual network name - You're running in a Docker Swarm environment where overlay networks need special handling External networks are useful when you want multiple Compose projects to share a common network, or when you need to connect containers managed by Compose to containers managed directly by Docker.

Typical symptoms

  • Running 'docker-compose up' fails immediately with network error
  • Error message shows the specific network name that couldn't be found
  • Services cannot start because the required network is missing
  • Works on one machine but fails on another (network wasn't created)
  • CI/CD pipeline fails at the docker-compose up step

Common causes

  1. The external network was never created with 'docker network create'
  2. Network name in docker-compose.yml doesn't match the actual network name
  3. The network was deleted or removed during cleanup
  4. Using Swarm overlay network without proper Swarm initialization
  5. Network was created by another Compose project that hasn't been started
  6. Typo in the network name (check for case sensitivity)
  7. Running on a new machine where the network doesn't exist yet

How to fix "ERROR: Network mynetwork declared as external, but could not be found"

1Create the missing network manually

The most direct fix is to create the network that Docker Compose is looking for:

bash
# Create a basic bridge network
docker network create mynetwork

# Verify it was created
docker network ls | grep mynetwork

Replace mynetwork with the actual network name from your error message.

For Swarm mode overlay networks:

bash
docker network create -d overlay --attachable mynetwork
2Verify the network name matches your Compose file

Check your docker-compose.yml to see how the network is defined:

yaml
networks:
  mynetwork:
    external: true

Or with an explicit name:

yaml
networks:
  mynetwork:
    name: my-actual-network-name
    external: true

List existing networks to find the correct name:

bash
docker network ls

If there's a name mismatch, either:
1. Update the Compose file to use the correct network name
2. Create a new network with the name Compose expects

3Remove external flag if you don't need a shared network

If you don't actually need to share this network with other projects or manually-created containers, remove the external: true flag:

Before (external network):

yaml
networks:
  mynetwork:
    external: true

After (Compose-managed network):

yaml
networks:
  mynetwork:
    driver: bridge

Or simply don't define the network at all - Docker Compose creates a default network automatically:

yaml
services:
  web:
    image: nginx
  api:
    image: myapi
# No networks section needed - services can communicate by service name
4Check for network naming convention issues

Docker Compose prefixes auto-created networks with the project name. If you're referencing a network created by another Compose project, include the full name:

bash
# List networks to see full names
docker network ls

# Output might show:
# myproject_default
# otherapp_shared

Update your Compose file to use the full network name:

yaml
networks:
  shared:
    name: otherapp_shared
    external: true

The name field specifies the actual Docker network name, while the key (shared) is just the alias within your Compose file.

5Start the dependent Compose project first

If the network is created by another docker-compose project, start that project first:

bash
# Start the project that creates the network
cd /path/to/other-project
docker-compose up -d

# Verify the network exists
docker network ls

# Now start your project
cd /path/to/your-project
docker-compose up -d

For a more robust solution, create a shared network in a startup script rather than depending on another Compose project.

6Handle Swarm overlay networks correctly

If you're using Docker Swarm, overlay networks require special handling:

bash
# Initialize swarm if not already done
docker swarm init

# Create an attachable overlay network
docker network create -d overlay --attachable mynetwork

# Verify it's an overlay network
docker network inspect mynetwork | grep Driver

In your Compose file:

yaml
networks:
  mynetwork:
    external: true
    # driver: overlay is inferred from the existing network

Note: On Swarm worker nodes, overlay networks may not be immediately visible until a service uses them. The network is created on the manager but only materializes on workers when needed.

Advanced notes

Multiple Compose files sharing a network: When multiple projects need to communicate, create a dedicated shared network:

bash
# Create once during system setup
docker network create shared-services

Then in each Compose file:

yaml
services:
  myservice:
    networks:
      - default        # Internal project network
      - shared         # Cross-project communication

networks:
  shared:
    name: shared-services
    external: true

CI/CD considerations: In CI pipelines, networks don't persist between runs. Either:
1. Remove external: true and let Compose manage the network
2. Add a setup step to create the network before docker-compose up
3. Use docker-compose up with the --force-recreate flag

Docker Compose version differences: In older Compose file versions (2.x), external networks were defined differently:

yaml
# Old format (deprecated)
networks:
  outside:
    external:
      name: actual-name-of-network

# New format (Compose file 3.5+)
networks:
  outside:
    name: actual-name-of-network
    external: true

Debugging network issues:

bash
# List all networks with details
docker network ls

# Inspect a specific network
docker network inspect mynetwork

# See which containers are connected to a network
docker network inspect mynetwork -f '{{range .Containers}}{{.Name}} {{end}}'

Frequently asked questions

What does "ERROR: Network mynetwork declared as external, but could not be found" mean?
yml file, you're telling Docker Compose that this network already exists and was created outside of the current Compose project. Docker Compose will not attempt to create it - instead, it expects to find an existing network with that name. The "declared as external, but could not be found" error means Docker Compose queried the Docker daemon for a network with the specified name and didn't find one.
How do I fix "ERROR: Network mynetwork declared as external, but could not be found"?
This error occurs when Docker Compose tries to connect a service to an external network that doesn't exist. External networks must be created manually using 'docker network create' before running docker-compose, or you can remove the external flag to let Compose create the network automatically.
What causes "ERROR: Network mynetwork declared as external, but could not be found"?
The external network was never created with 'docker network create' Network name in docker-compose.yml doesn't match the actual network name The network was deleted or removed during cleanup
Is the "ERROR: Network mynetwork declared as external, but could not be found" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading