Unable to create a container (name "NAME” is already used by ID). with nerdctl

1.2k Views Asked by At

I am using nerdctl as docker desktop alternative

I am facing the following error while running nerdctl compose up

Unable to create a container (name "v2_mongo_1” is already used by ID"asdfasdfadfa"). with nerdctl

I have check with nerdctl ps -a, there are no containers running, so am not able to find out how to get rid of this error.

mongo:
    image: 'mongo:4.2.3-bionic'
    ports:
      - '27017:27017'
    volumes:
      - ./mongod.conf:/etc/mongod.conf
      - ./mongo-init-local-replicaset.sh:/etc/mongo-init-local-replicaset.sh:default
      - ./docker/mongo:/data/db
    entrypoint: ["mongod","-f","/etc/mongod.conf"]
    healthcheck:
      test:  ["CMD", "/etc/mongo-init-local-replicaset.sh"]
      start_period: 3s
2

There are 2 best solutions below

0
On

Adding my answer here as I encountered something similar and had to piece together a solution. This post came up when I googled the problem.

The other answer from @vinod didn't work for me, as there isn't an existing container, and so I can't remove it!

There is a github issue that gives a particular file path to delete: https://github.com/containerd/nerdctl/issues/499

Doing this worked for me, but the filepath cited in that issue was not the same as my local lima+nerdctl setup.

For anyone else finding this issue, I suggest you try going into the following directory in your lima guest:

~/.local/share/nerdctl/1935db59/names/default

and deleting whatever file in there matches the name that is clashing (which would be v2_mongo_1 for the OP.

Hope this helps.

1
On

Use nerdctl rm v2_mongo_1 first to remove the existing container.