即使删除了所有图像和容器,Docker 也占用了太多空间

即使删除了所有图像和容器,Docker 也占用了太多空间

我最近开始使用 Docker,即使我删除了所有悬空的容器和图像,Docker 仍然占用了太多空间。

当尝试运行时sudo docker system prune --all -f它显示"container prune" requires API version 1.25, but the Docker daemon API version is 1.24但显然我的 Docker 是版本 1.44 当我运行时sudo docker version

当我运行时,每个类别都是零docker system df

我多次使用 Docker 来生成 Python 容器并安装 Flask 之类的库,它也可以访问 docker.sock 来生成新容器。

这是否占用了所有空间?如果是这样,如何收回空间?

sudo docker info输出如下

Client: Docker Engine - Community
 Version:    25.0.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2-desktop.5
    Path:     /usr/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.23.0-desktop.1
    Path:     /usr/lib/docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /usr/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     /usr/lib/docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.9
    Path:     /usr/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/lib/docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /usr/lib/docker/cli-plugins/docker-scan
  scout: Docker Scout (Docker Inc.)
    Version:  v1.0.9
    Path:     /usr/lib/docker/cli-plugins/docker-scout

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.24
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc version: 
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 6.5.0-14-generic
 Operating System: Ubuntu Core 22
 OSType: linux
 Architecture: x86_64
 CPUs: 20
 Total Memory: 15.24GiB
 Docker Root Dir: /var/snap/docker/common/var-lib-docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

答案1

你的docker info命令显示了一些“有趣”的东西(读作:错误)。它说:

Client: Docker Engine - Community
 Version:    25.0.0
...
   Path:     /usr/lib/docker/cli-plugins/docker-compose

但随后它又说:

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.24
 ...
 Docker Root Dir: /var/snap/docker/common/var-lib-docker

巧合的是,客户端版本与 Docker 存储库中的最新版本相匹配,但服务器版本与snapDocker 的最新稳定版本相匹配。

结合给定的路径(一个有/usr/lib,另一个有/var/snap),我相信您已经将 Docker 安装为来自 Docker 存储库的snap包和普通包。.deb

我的建议是删除该snap软件包,然后重新安装 Docker 以确保一切正常。

sudo snap remove docker
sudo apt-get install --reinstall docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

现在我相信 Docker 只需最新版本就能够正常工作。

看到这个问题,有点类似。

答案2

替代原因:用户不属于docker该组

docker system prune没有明确说明,而是给出模棱两可的"container prune" requires API version 1.25, but the Docker daemon API version is 1.24错误

添加用户至docker组或使用sudo

相关内容