添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
踢足球的洋葱  ·  风中呓语·  1 周前    · 
性感的黄豆  ·  How to stop the ...·  2 天前    · 
玩命的火车  ·  Docker build is not ...·  昨天    · 
乐观的甘蔗  ·  Alpine Docker ...·  昨天    · 
谈吐大方的鸵鸟  ·  Dynamics Community ...·  10 月前    · 
爽快的野马  ·  Plex unable to ...·  1 年前    · 
留胡子的煎饼  ·  美国棕榈泉_百度百科·  1 年前    · 

How to fix Docker error cannot delete docker container conflict unable to remove repository reference?

calendar
Docker error cannot delete docker container conflict unable to remove repository reference

This error comes when you try to delete/remove your docker image before removing your docker container . The basic principle of docker says you should always remove your docker container first before removing the docker image.

In this article, we are going to see how to fix this issue along with the recommended way to handle the removal/deletion of the docker container and docker images.

Now the question comes - What is the difference between Docker images and Docker container?

Answer - Docker container is a runnable instance of Docker image. So if draw the tree hierarchy of Docker image and Docker container then Docker Image will sit at the top and Docker Container will sit underneath. So if want to remove the Docker image then first you should need to remove the Docker Container and then the Docker image associated with the Docker container.

Let's break down all the steps and target each step to fix the issue -

Table content

  • Step 1 - List all the container
  • Step 2 - List all the images
  • Step 3 - Pick the container which you want to delete/remove
  • Step 4 - Remove the corresponding docker images associated with the docker container
  • Step 5 - If nothing works then use last resort use docker system prune
  • 1. Step 1 - List all the container

    Before we start troubleshooting the error the first step which we need is to check all the running container. Use the following docker command to check all the running container inside your machine -

    1docker ps -a
    

    This will list out all of your running containers as well exited containers -

    1 CONTAINER ID        IMAGE                                COMMAND                CREATED             STATUS              PORTS                    NAMES
    2794e4a93f514        jhooq-spring-boot-docker-compose:1   "java -jar /app.jar"   18 minutes ago      Up 18 minutes       0.0.0.0:8080->8080/tcp   hooq-k8s_jhooq-springboot-container_1
    

    (Note: For the example purpose I am taking only one container jhooq-spring-boot-docker-compose )

    2. Step 2 - List all the images

    Alright now we know all the containers which are running, now we should check all the images associated with the docker container.

    And the command for checking the images is -

    1docker image ls 
    

    The above command will list out all the docker images which are available and also associated with your docker container. Here is the following output which I got after running the docker image ls command

    1REPOSITORY          TAG                     IMAGE ID       CREATED       SIZE
    2jhooq-docker-demo   jhooq-docker-demo       8dab1cc236da   2 days ago    93.6MB
    

    Since I have created this article with only one docker container and one docker image but in your case you might see more number of images once you run the command docker image ls

    3. Step 3 - Pick the container which you want to delete/remove

    Now you should pick the container name from Step 1 which you want to delete. For this guide, the container which I am running is jhooq-spring-boot-docker-compose with the container id 794e4a93f514 .

    To remove the container we are going to use the container id (Note : Please replace your container ID with your suitable container ID) -

    1 docker rm 794e4a93f514
    

    The above command will first stop the container with container id 794e4a93f514

    4. Step 4 - Remove the corresponding docker images associated with the docker container

    Okay so now we have deleted the docker container in step 3 , lets delete/remove the docker images associated with the container.

    (Note: Always make sure that you have stopped and removed the container before removing the image. Also in the following command please update your image id before running it.)

    1docker rmi 8dab1cc236da 
    

    If you can complete all the 4 steps in the same sequence then your error cannot delete docker container conflict unable to remove repository reference must be resolved now.

    But if by any chance the above steps do not work for you and you are still stuck with the same issue then I would recommend you to use docker system prune which we are going to see in Step 5 .

    Step 5 - If nothing works then use last resort use docker system prune

    If you come this far then I can guess you have tried all the 4 steps mentioned in this blog but you are still stuck with the issue.

    There is one more command docker system prune which can help you to fix the issue but this command should be used as a last resort because if you use it without knowing it impact then your might lose a lot rather than fixing the issue.

    The simplest way to use the command is -

    1docker system prune -a  
    

    It will delete/remove all the containers, network, unused images and build caches.

    But we can customize the docker system prune command by supplying different parameters to it. Read this article - On how to use docker prune .

    Here are some reference for further reading -

  • Stackoverflow - Docker error cannot delete docker container, conflict: unable to remove repository reference
  • GitHub - Docker rmi unable to remove images
  • (docker run -d) Why Does a Docker Container Stop Automatically?
  • Attach and detach from Docker's process?
  • How I Change Name of My Docker Repository and Rename Images?
  • How to set-up Cron Jobs in Docker Containers?
  • 4 Ways to copy file from localhost to docker container
  • Multiple commands execution in Docker Compose?
  • How to push Docker Images to AWS ECR(Elastic Container registry)?
  • How to Copy Docker images from one host to another host?
  • What is persistent storage in docker and how to manage it
  • Docker Installation on MacOS, Linux and Windows
  • Docker - ADD, Update, Export Environment variable
  • How to fix-Docker docker failed to compute cache key not found
  • How to fix docker driver failed programming external connectivity on endpoint webserver?
  • How to fix docker error executable file not found in $PATH?
  • How to expose port on live containers?
  • How to expose multiple ports with Docker?
  • How to restart single docker container within multiple docker container?
  • How to edit file within Docker container or edit a file after I shell into a Docker container?
  • How to fix Error starting docker service Unit not found?
  • How to remove old, unused images of Docker?
  • How to fix docker error invalid reference format error?
  • How to fix requested access to the resource is denied?
  • How to fix Docker error cannot delete docker container conflict unable to remove repository reference?
  • How to fix docker error no space left on device?
  • How to connect localhost from docker container?
  • Docker COPY vs Docker ADD?
  • 6 Ways to fix - Got permission denied while trying to connect to the Docker daemon socket?
  • 6 Ways to fix – Docker COPY failed: stat no source files were specified
  • Fixing the Terraform Error creating IAM Role. MalformedPolicyDocument Has prohibited field Resource In terraform how to handle null value with default value? Terraform use module output variables as inputs for another module? Its all about Open Source and DevOps, here I talk about Kubernetes, Docker, Java, Spring boot and practices. Read More