docker error - 'name is already in use by container'

后端 未结 18 2024
暖寄归人
暖寄归人 2020-12-12 08:14

Running the docker registry with below command always throws an error:

dev:tmp me$ docker run \\
     -d --name registry-v1 \\
     -e SETTINGS_         


        
相关标签:
18条回答
  • 2020-12-12 09:03

    The Problem: you trying to create new container while in background container with same name is running and this situation causes conflicts.

    The error would be like:

    Cannot create continer for service X :Conflict. The name X is already in use by container abc123xyz. You have to remove ot delete (or rename) that container to be able to reuse that name.

    Solution rename the service name in docker-compose.yml or delete the running container and rebuild it again (this solution related to Unix/Linux/macOS systems):

    1. get all running containers sudo docker ps -a
    2. get the specific container id
    3. stop and remove the duplicated container / force remove it
    sudo docker stop <container_id>
    sudo docker rm <container_id>
    

    or

    sudo docker rm --force <container_id>
    
    0 讨论(0)
  • 2020-12-12 09:03

    Ok, so I didn't understand either, then I left my pc, went to do other things, and upon my return, it clicked :D

    1. You download a docker image file.

    2. Now, you use docker run, and give it a name (e.g: newWebServer).

      docker run -d -p 8080:8080 -v --name newWebServer new/webserver-image

    OK. So now, docker run just created a container from your image. If it isn't running, you can now start it with it's name:

    docker start newWebServer
    

    You can check all your containers (they may or may not be running) with

    docker ps -a
    

    You can stop and start them with their name or the container id from the CONTAINER ID column now e.g:

    docker stop newWebServer
    
    docker start c3028a89462c
    

    And list all your images, with

    docker images -a
    

    In a nutshell, download an image; docker run creates a container from it; stop it with docker stop (name or container id); start it with docker start (name or container id).

    0 讨论(0)
  • 2020-12-12 09:10

    TL:DR;

    List all containers:
    docker ps -a
    Remove the concerned container by id:
    docker container rm <container_id>

    0 讨论(0)
  • 2020-12-12 09:10

    Simple Solution: Goto your docker folder in the system and delete .raw file or docker archive with large size.

    0 讨论(0)
  • 2020-12-12 09:10

    The OP's problem is the error. Deleting state isn't the only solution - or even a good one. The problem is docker run isn't re-entrant, and docker start is impotent w/o run. So we have to combine them.

    For example to run Postgres w/o destroying previous state, try this:

    docker start postgres || docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=password postgres:13-alpine
    
    0 讨论(0)
  • 2020-12-12 09:13

    Here what i did, it works fine.

    step 1:(it lists docker container with its name)

    docker ps -a
    

    step 2:

    docker rm name_of_the_docker_container
    
    0 讨论(0)
提交回复
热议问题