docker常用操作命令

参考文档:

常用命令

查看容器列表

docker ps
docker container ls

docker container prune //删除没用的容器


查看镜像列表
docker images
docker image ls
docker images -a

docker image prune //删除没用的镜像

docker image rm hello-world //删除hello-world镜像
docker rmi Image image_a


停止和删除容器  
docker container ls
docker container stop webserver
docker container ls -a
docker container rm webserver
docker image ls
docker image rm nginx

Images, Containers, Volumes,Networks的删除

参考:

删除所有没有使用及悬挂状态的Images, Containers, Volumes,Networks
docker system prune

删除所有非运行状态下的Images, Containers, Volumes,Networks
docker system prune -a

Removing Docker Images
List:
docker images -a

Remove:
docker rmi Image [IMAGE]

Remove dangling images
List:
docker images -f dangling=true

Remove:
docker images purge

Removing images according to a pattern
List:
docker images -a | grep "pattern"

Remove:
docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi

Remove all images
List:
docker images -a

Remove:
docker rmi $(docker images -a -q)

Removing Containers
List:
docker ps -a

Remove:
docker rm ID_or_Name ID_or_Name

Remove a container upon exit
Run and Remove:
docker run --rm image_name

Remove a container upon exit
Run and Remove:
docker run --rm image_name

Removing Volumes
List:
docker volume ls

Remove:
docker volume rm volume_name volume_name

Remove dangling volumes - Docker 1.9 and later
List:
docker volume ls -f dangling=true

Remove:
docker volume prune

Remove a container and its volume
Remove:
docker rm -v container_name


查看镜像的环境变量
docker run IMAGE env

查看容器的PID
docker inspect --format '{{.State.Pid}}' 023d86450a1c

查看容器的IP
docker inspect --format '{{.NetworkSettings.IPAddress}}' 023d86450a1c

版权所有,转载请注明出处 luowei.github.io.