美文网首页
Docker的container和image的相关命令

Docker的container和image的相关命令

作者: 一个废人 | 来源:发表于2018-07-09 15:23 被阅读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

相关文章

网友评论

      本文标题:Docker的container和image的相关命令

      本文链接:https://www.haomeiwen.com/subject/hjctpftx.html