60

I was building docker image using the command

docker-compose -f "docker-compose.yml" up -d --build 

But it returns me an error

ERROR: 2 matches found based on name: network officeconverter_default is ambiguous

This is a bit clear that in my machine there are two networks with the same name trying to exists.

Question is how to remove the networks from docker networks

PS E:\repos\Github\officeconverter> docker network ls
NETWORK ID          NAME                        DRIVER              SCOPE
868c88a83bd6        bridge                      bridge              local
92f7d20ed432        officeconverter_default     bridge              local
3f96cfb7b591        officeconverter_default     bridge              local

AthulMuralidhar
  • 662
  • 1
  • 9
  • 26
Dupinder Singh
  • 7,175
  • 6
  • 37
  • 61
  • 2
    I encountered the same issue. I created the problem by running the same `docker-compose -f up -d` command simultaneously. As an aside this was because a jest test suite attempted to execute two integration tests in parallel, where a setup step of the integration test was to perform a docker compose. I was able to solve the issue by running `docker network prune` but be wary this may remove more networks than you wanted. This was ok for me because I was on a dev laptop with nothing important WRT docker config. Hope this helps – zayquan Jan 06 '21 at 00:01

7 Answers7

69

The solution is simple!

just remove the networks.

like docker network rm <network Id> <space> <network Id> ....

PS E:\repos\Github\officeconverter> docker network rm 92f7d20ed432 3f96cfb7b591
92f7d20ed432
3f96cfb7b591
PS E:\repos\Github\officeconverter> docker network ls
NETWORK ID          NAME                        DRIVER              SCOPE
868c88a83bd6        bridge                      bridge              local
Dupinder Singh
  • 7,175
  • 6
  • 37
  • 61
54

try:
docker network prune

This will remove all your networks.

baumannalexj
  • 766
  • 1
  • 9
  • 20
4

A solution that worked for me is:

docker system prune -af
docker volume prune --force.

claudius
  • 747
  • 1
  • 10
  • 24
1

Open cronjob with sudo cronjob -e, then, add new line

*/1 * * * * docker network prune -f

This will clean non-used networks (if any) every minute.

Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
1

As others have said, you can docker network rm <network id> to actually delete them.

But if you need to choose which one to delete, you can:

$ docker network inspect d5867f0be024
[
    {
        "Name": "minikube",
        "Id": "d5867f0be024b1c81237fba1eaef3f1ff53b75e15ab84d46a13dcde53809934e",
        "Created": "2022-02-16T19:24:57.7203334-05:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        ...
    }
]

... and then see the Created time (or other metadata) to make your decision about which to delete.

In my case I needed to delete the newer one and retain the older one.

Jim K.
  • 924
  • 8
  • 8
1

One option is to create a new network, with a different network name, and to connect your docker container to it.
There is a similar error that can happen with ambiguous bridge network names.
One guy has made a complete blog post about how to fix this.
I found it very useful as far as I am concerned, and I believe this will be useful to others in similar situation even if you deal with a network that is not bridge: https://www.jorgeanaya.dev/en/bin/docker-network-name-is-ambiguous/

Here is the short workaround from the blog post (all credit goes to Jorge Anaya):

  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.
Don't forget to add sudo at the beginning of each command for permissions.

Yoann Pageaud
  • 412
  • 5
  • 22
-1

Just run docker remove prune it will remove all networks and create again.

Shiva D
  • 9
  • 2