The docker network create command failed because the network name you specified, or a network with that name already exists on your Docker host.

Here’s how to nail down the cause and fix it:

1. The Network Actually Exists (Most Common)

You’re trying to create a network that’s already there, maybe from a previous failed docker-compose up or a manual docker network create you forgot about.

  • Diagnosis: List all networks and look for your name:
    docker network ls
    
  • Fix:
    • Option A (Remove it): If you don’t need the old network, remove it.
      docker network rm <network_name>
      
      This frees up the network name, allowing docker network create to succeed.
    • Option B (Use the existing one): If the network should exist and you want to use it, stop trying to create it. Your application (e.g., docker-compose up) should be able to attach to it. If it’s a manual creation, you’ll need to inspect the existing network to ensure it’s configured as you expect.
      docker network inspect <network_name>
      
      This command shows you all the details about the existing network, including its driver, subnet, gateway, and connected containers, allowing you to verify its configuration.

2. Docker Daemon State Inconsistency

Sometimes, Docker’s internal state gets a little wonky. It might think a network exists when it doesn’t, or vice-versa, leading to this error even after you’ve checked docker network ls and confirmed it’s not there.

  • Diagnosis: Check Docker daemon logs for any related errors around the time you tried to create the network. The location varies by OS, but often found in /var/log/docker.log or via journalctl -u docker.service.
  • Fix: Restart the Docker daemon. This often clears up internal inconsistencies.
    • Linux (systemd):
      sudo systemctl restart docker
      
    • macOS/Windows: Use the Docker Desktop GUI to restart the engine. This forces Docker to re-initialize its state, resolving phantom network entries.

3. Docker Compose Leftover Network

If you’re using docker-compose, it manages networks for your services. A previous docker-compose up might have created a network, and if the docker-compose.yml file has changed or the compose project was interrupted, Docker might still see that network.

  • Diagnosis: Look for a network named <project_name>_<network_name> in the output of docker network ls. The <project_name> is usually the directory name where your docker-compose.yml resides.
  • Fix:
    • Option A (Clean up compose project):
      docker-compose down -v
      docker-compose up -d
      
      docker-compose down -v stops and removes all containers, networks, and volumes associated with the compose project. This ensures a clean slate before docker-compose up -d recreates everything.
    • Option B (Manual removal if docker-compose down fails): If docker-compose down doesn’t clean up, you might need to manually remove the network identified in the diagnosis step.
      docker network rm <project_name>_<network_name>
      
      Then try docker-compose up -d again.

4. Conflicting Network Driver or Configuration

You might be trying to create a network with specific options (like a custom subnet or gateway) that conflict with an existing network or Docker’s network configuration. This is less common for a simple "network already exists" error but can manifest if Docker tries to create a network similar to an existing one and gets confused.

  • Diagnosis: Compare the docker network inspect output of any existing networks with similar names or configurations to the docker network create command you’re attempting. Pay close attention to IPAM (IP Address Management) configurations.
  • Fix: Adjust your docker network create command to avoid conflicts.
    • If you’re specifying a subnet, ensure it doesn’t overlap with existing Docker networks or your host’s network. For example, if you have a bridge network using 172.17.0.0/16, don’t try to create another bridge network using the same subnet.
    • Remove the conflicting IPAM configuration if you don’t strictly need it.
    # Example: Avoid creating a network with a subnet already in use
    docker network create --driver bridge --subnet 172.20.0.0/16 my_custom_network
    
    This command creates a new bridge network named my_custom_network using the specified IPAM configuration, assuming 172.20.0.0/16 is not already in use by another Docker network.

5. Corrupted Docker Network Configuration Files

In rare cases, the actual configuration files on disk that represent Docker’s networks can become corrupted.

  • Diagnosis: This is hard to diagnose directly without deep Docker internals knowledge. Look for filesystem errors or unusual file sizes in Docker’s data directories (e.g., /var/lib/docker/network on Linux).
  • Fix: A more drastic measure is to prune all unused networks and then restart Docker.
    docker network prune
    sudo systemctl restart docker
    
    docker network prune removes all networks not used by at least one container. This is a more aggressive cleanup than docker network rm and can resolve issues stemming from corrupted internal network state if restarting the daemon alone didn’t work.

6. Docker Swarm Interference

If you are running Docker Swarm, networks can behave differently and might be managed by Swarm’s internal state rather than direct docker network commands. A network might be marked as "global" or "ingress" and appear to exist when you try to create it locally.

  • Diagnosis: Check if your Docker daemon is part of a Swarm.
    docker info | grep Swarm
    
    If Swarm is active, inspect networks with Swarm context in mind.
  • Fix:
    • If it’s a Swarm network you’re trying to create locally, you likely need to create it as a Swarm network.
      docker network create --driver overlay my_overlay_network
      
      This command creates a distributed overlay network compatible with Swarm.
    • If you are not intending to use Swarm and it’s active, you might need to leave the Swarm.
      docker swarm leave --force
      
      This command forces the current node to leave the Swarm cluster.

After fixing, you’ll likely encounter a "port is already allocated" error if you’ve tried to map a host port that’s already in use by another container.

Want structured learning?

Take the full Docker course →