我想在Docker中删除容器,但是当你想删除时发生了一个错误
在移除容器之前,我的下一步是查看现有容器的列表
sts@Yudi:~/docker$ sudo docker ps -as
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
78479ffeba5c ubuntu "/bin/bash" 42 hours ago Exited (0) 42 hours ago sharp_wescoff 81 B (virtual 187.7 MB)
0bd2b54678c7 training/webapp "python app.py" 5 days ago Exited (0) 5 days ago backstabbing_ritchie 0 B (virtual 323.7 MB)
0adbc74a3803 training/webapp "python app.py" 5 days ago Exited (143) 5 days ago drunk_feynman 0 B (virtual 323.7 MB)
一个我想删除列表,即“training / webapp”
但是出现了一个错误
sts@Yudi:~/docker$ sudo docker rmi training/webapp
Error response from daemon: conflict: unable to remove repository reference "training/webapp" (must force) - container 0bd2b54678c7 is using its referenced image 54bb4e8718e8
Error: failed to remove images: [training/webapp]
容器是否在映像中运行?
请帮助
Noticed this is a 2-years old question, but still want to share my workaround for this particular question:
Firstly, run docker container ls -a to list all the containers you have and pinpoint the want you want to delete.
Secondly, delete the one with command docker container rm <CONTAINER ID> (If the container is currently running, you should stop it first, run docker container stop <CONTAINER ID> to gracefully stop the specified container, if it does not stop it for whatever the reason is, alternatively you can run docker container kill <CONTAINER ID> to force shutdown of the specified container).
Thirdly, remove the container by running docker container rm <CONTAINER ID>.
Lastly you can run docker image ls -a to view all the images and delete the one you want to by running docker image rm <hash>.
docker镜像和docker容器是有区别的。检查这个SO问题。
简而言之,容器是映像的可运行实例。这就是为什么如果映像中有正在运行的容器,则不能删除映像的原因。您只需要首先删除容器。
docker ps -a # Lists containers (and tells you which images they are spun from)
docker images # Lists images
docker rm <container_id> # Removes a stopped container
docker rm -f <container_id> # Forces the removal of a running container (uses SIGKILL)
docker rmi <image_id> # Removes an image
# Will fail if there is a running instance of that image i.e. container
docker rmi -f <image_id> # Forces removal of image even if it is referenced in multiple repositories,
# i.e. same image id given multiple names/tags
# Will still fail if there is a docker container referencing image
Docker 1.13+更新[自2017年1月起]
在Docker 1.13中,我们重新组合了每个命令,使其位于与其交互的逻辑对象之下
基本上,上面的命令也可以重写,写得更清楚:
docker container ls -a
docker image ls
docker container rm <container_id>
docker image rm <image_id>
此外,如果你想删除所有你可以使用:
docker system prune -a
警告!这将删除:
所有停止的集装箱
所有网络不被至少一个容器使用
所有未使用的图像
所有构建缓存