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

DockerBEGINNERMEDIUMUpdated Dec 6, 2025ยท 395 views

This error occurs when your Docker Compose file references a network marked as external, but Docker cannot find a pre-existing network with that name. The fix is to either create the network manually or remove the external flag.

Quick fix

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

docker network ls
  1. List existing networks to verify the network name
  2. Create the missing external network
  3. Verify the network name matches your docker-compose.yml
  4. Remove the external flag if you don't need a shared network
docker โ€” error
docker network ls
Network mynetwork declared as external, but could not be found

What this error means

The "Network declared as external but could not be found" error occurs when Docker Compose tries to connect services to a network that is marked with `external: true`, but no such network exists on the Docker host. When you declare a network as `external` in your docker-compose.yml, you're telling Compose: "This network already exists - don't create it, just connect to it." However, if the network doesn't actually exist, Compose cannot proceed and throws this error. This is a common source of confusion because Compose normally creates networks automatically. The `external: true` flag changes this behavior, making you responsible for creating the network beforehand. This is particularly useful when: - Multiple Compose projects need to share the same network - You need a network with specific configuration that Compose doesn't support - You want to integrate Compose-managed containers with manually created ones

Typical symptoms

  • docker-compose up fails immediately with 'Network declared as external, but could not be found'
  • Error message includes the exact network name that's missing
  • Services fail to start because they can't join the specified network
  • The same docker-compose.yml worked on another machine but fails on this one
  • Error appears after cloning a project or setting up a new development environment

Common causes

  1. The external network was never created with 'docker network create'
  2. The network name in docker-compose.yml doesn't match the actual network name
  3. The network was removed or pruned and not recreated
  4. A typo or case mismatch in the network name (Docker network names are case-sensitive)
  5. Using environment variable interpolation for network name, but the variable is not set
  6. The network exists in a different Docker context or on a different Docker host

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

1List existing networks to verify the network name

First, check what networks currently exist on your Docker host:

bash
docker network ls

Look for the network name mentioned in the error. If it's not listed, you'll need to create it. Pay attention to the exact spelling and case - network names are case-sensitive.

You can also filter for a specific name:

bash
docker network ls --filter name=mynetwork
2Create the missing external network

Create the network that your docker-compose.yml expects:

bash
docker network create mynetwork

For a bridge network (the default), this is all you need. If you need specific options:

bash
# Create with a specific subnet
docker network create --subnet=172.28.0.0/16 mynetwork

# Create with a specific driver
docker network create --driver bridge mynetwork

After creating the network, run docker-compose up again.

3Verify the network name matches your docker-compose.yml

Check your docker-compose.yml to ensure the network name matches exactly:

yaml
networks:
  mynetwork:
    external: true

If you're using the name property, verify it matches the created network:

yaml
networks:
  app_network:
    name: mynetwork
    external: true

In this case, the internal reference is app_network, but Docker looks for a network named mynetwork.

Use docker compose config to see the resolved configuration including any variable substitutions:

bash
docker compose config
4Remove the 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, simply remove external: true:

Before:

yaml
networks:
  mynetwork:
    external: true

After:

yaml
networks:
  mynetwork:
    driver: bridge

Or remove the networks section entirely - Compose will create a default network automatically:

yaml
services:
  web:
    image: nginx
  db:
    image: postgres
# No networks section needed - Compose creates a default network
5Use the name property for cleaner network naming

Since Docker Compose version 3.5+, you can use the name property to control the exact network name without the project prefix:

yaml
networks:
  shared:
    name: shared_network
    driver: bridge

This creates a network called exactly shared_network (not projectname_shared_network). When you need to share it across projects, other Compose files can reference it as external:

yaml
networks:
  shared:
    name: shared_network
    external: true

This approach avoids needing to manually create networks in most cases - the first Compose project to start will create it.

6Handle shared networks across multiple Compose projects

When multiple Compose projects need to communicate, create a shared external network:

bash
# Create the shared network once
docker network create shared_net

Then in each docker-compose.yml:

yaml
services:
  app:
    image: myapp
    networks:
      - shared_net
      - default  # Also keep the default network for internal services

networks:
  shared_net:
    external: true

Services on the shared network can reach each other using their service names as hostnames.

Advanced notes

Automating network creation in CI/CD: In CI/CD pipelines, create the network before running compose:

bash
docker network inspect mynetwork >/dev/null 2>&1 || docker network create mynetwork
docker compose up -d

Using environment variables for network names: If you use variables in network names, ensure they're set:

yaml
networks:
  app_net:
    name: ${NETWORK_NAME:-default_network}
    external: true

Check the resolved name with docker compose config.

Network driver considerations: External networks can use any driver. If you're using overlay networks for Swarm or custom network plugins, ensure the driver is available:

bash
docker network create --driver overlay --attachable mynetwork

The --attachable flag allows standalone containers (not just Swarm services) to connect.

Docker contexts and remote hosts: If you're using Docker contexts to manage multiple Docker hosts, the network must exist on the host you're currently targeting:

bash
# Check current context
docker context show

# List networks on current context
docker network ls

# Switch context if needed
docker context use production

Compose V2 vs V1: Docker Compose V2 (docker compose) handles networks slightly differently than V1 (docker-compose). V2 is more strict about external network existence checks. If upgrading from V1, you may need to create networks that V1 was silently creating or ignoring.

Cleanup and troubleshooting: If you suspect stale network state:

bash
# Remove unused networks
docker network prune

# Force remove a specific network (disconnect all containers first)
docker network rm mynetwork

# Recreate fresh
docker network create mynetwork

Frequently asked questions

What does "Network mynetwork declared as external, but could not be found" mean?
The "Network declared as external but could not be found" error occurs when Docker Compose tries to connect services to a network that is marked with external: true, but no such network exists on the Docker host. " However, if the network doesn't actually exist, Compose cannot proceed and throws this error. This is a common source of confusion because Compose normally creates networks automatically.
How do I fix "Network mynetwork declared as external, but could not be found"?
This error occurs when your Docker Compose file references a network marked as external, but Docker cannot find a pre-existing network with that name. The fix is to either create the network manually or remove the external flag.
What causes "Network mynetwork declared as external, but could not be found"?
The external network was never created with 'docker network create' The network name in docker-compose.yml doesn't match the actual network name The network was removed or pruned and not recreated
Is the "Network mynetwork declared as external, but could not be found" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading