Docker的container和image的相关命令

2018-07-09  本文已影响8人  一个废人

There is a difference between docker images and docker containers. Check this SO Question.
In short, a container is a running instance of an image. which is why you cannot delete an image if there is a running container from that image. You just need to delete the container first.

Docker ps -a               # Lists containers (and tells you which images they are spun from)
Docker images              # Lists images  
Docker rm <container_id>   # Removes a container

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

详见:https://stackoverflow.com/questions/33907835/docker-error-cannot-delete-docker-container-conflict-unable-to-remove-reposito

上一篇 下一篇

猜你喜欢

热点阅读