Docker network name is ambiguous
 
  March 25, 2020

The Issue

I was working on my Linux server, and I had to restart it. The docker instance was empty when the server came back, and it didn't show any container. I was in shock, and I thought I had lost my images and containers. After reviewing the system's health couldn't found a root cause, so I did a second restart 😅 and that's it the containers were back. Great! But when I tried to start my containers …


ERROR: network xxxx is ambiguous (2 matches found based on name)

The Whys

I found that docker allows repeating network names 👻; my hunch here is that when the system restarted something (maybe my container disk didn't mount properly), docker recreated the network configuration. As you can see in the following table, it duplicated every network and driver

 docker network list

            

$ docker network ls
NETWORK ID NAME DRIVER SCOPE
27b6c27fdc2b bridge bridge local
33f2a0c04878 bridge bridge local
c4247d693521 host host local
9b95be563bf7 host host local
590102262bb5 none null local
25e1bf9dc86 none null local
            
            
        

So the solution appeared to be, just to delete one of the duplicate networks by his ID. I tried to execute the following command docker network rm [ID]


Error : bridge is a pre-defined network and cannot be removed

What the … this was more tricky than what I initially thought, at some forum, I found some arbitrary advice:

  1. The docker service must be stopped
  2. There shouldn't be a container using the network
  3. And another workaround is not to have containers (delete them)

If you need to see which containers are using which network use:

 Inspect network ID of a container

            

# Note that in this scenario since bridge is repeated you'll need to do it by Id:
docker network inspect [id || name]

"Internal": false,
{ "Network": "" },
"ConfigOnly": false,
"Containers": {},

            
            
        

So, at this point option one and two didn't work and I couldn't afford to delete all my containers which there were already configured with his own volumes and startup scripts.

Workaround and Solution

  1. Create a new network. Use the parameter -d to specify the driver

    docker network create -d bridge [new-network-name]

  2. Disconnect the container(s) from the ambiguous network

    docker network disconnect bridge [container-name]

  3. Connect the container(s) to the new network

    docker network connect [new-network-name] [container-name]

  4. Optional. Purge our network and get rid off of the unused networks

    docker network rm $(docker network ls -q)

And that's all, now we should be able to start our containers.


docker start my-happy-container