使用Docker Toolbox for Windows和Virtualbox,我运行了以下命令来清理docker:
集装箱
docker rm -v $(docker ps -a -q -f status=exited)
图片
docker rmi $(docker images -f "dangling=true" -q)
卷
docker volume rm $(docker volume ls -qf dangling=true)
然而,似乎我的磁盘仍然被我构建的图像所消耗?我还运行了以下脚本进行清理:
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)'
) | xargs -r rm -fr
我收到以下错误:
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/json?all=1&filters=%7B%22status%22%3A%7B%22dead%22%3Atrue%2C%22exited%22%3Atrue%7D%7D: open //./pipe/docker_engine: The system cannot find the file specified.
我相信这是因为我在非Linux系统上使用了Docker Toolbox。因此我的未使用卷的路径已关闭?
Docker Toolbox在哪个目录中存储它创建的图像?
答案 0 :(得分:1)
您还可以尝试添加到1.13.0版的一些命令:
$ docker system prune
$ docker container prune
$ docker image prune
$ docker volume prune
$ docker network prune
答案 1 :(得分:0)
在Linux上,我的dockerclean脚本是这样的:
#!/bin/bash
# Remove dead containers
docker ps -f status=dead --format '{{ .ID }}' | xargs -r docker rm -v
# Remove dangling volumes
docker volume ls -qf dangling=true | xargs -r docker volume rm
# Remove untagged images
docker images --digests --format '{{.Repository}}:{{.Tag}}@{{.Digest}}' | sed -rne 's/([^>]):<none>@/\1@/p' | xargs -r docker rmi
# Remove dangling images
docker images -qf dangling=true | xargs -r docker rmi
# Remove temporary files
rm -f /var/lib/docker/tmp/*