Docker 删除守护进程

Docker Delete daemon

我想删除一个 Docker 守护进程;因为它在我的电脑上需要更多 space 我确实插入了代码来安装 php:5.3-apache

我使用了这个命令 docker build -t my-php-app .

我收到这个错误

Sending build context to Docker daemon  7.039GB
Error response from daemon: unexpected error reading Dockerfile: read /var/lib/docker/tmp/docker-builder079515785/dockerfile: is a directory

所以我想删除那个守护进程,因为它在我的电脑上占用很大 space;我确实尝试了 3 次安装它,每次我都遇到同样的错误,所以我现在有超过 21GB 的空间需要清理。

docker 图片给我 :

orsolin/docker-php-5.3-apache   latest              d8e72369c6e9        2 years ago         533MB

但是我电脑上的 space 已从 30GB 减少到 8GB

我没有看到任何 7GB 大小的东西

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
abv_web                         latest              2194cdd678e3        45 hours ago        5.09GB
<none>                          <none>              58b330f4aa2f        46 hours ago        623MB
<none>                          <none>              c4b5c889111d        46 hours ago        623MB
<none>                          <none>              cfe4161b5af4        46 hours ago        623MB
<none>                          <none>              f37f2a95529a        46 hours ago        623MB
httpd                           latest              19459a872194        4 days ago          154MB
phpmyadmin/phpmyadmin           latest              d8d2c1fd1eb9        9 days ago          458MB
phpmyadmin/phpmyadmin           edge                4b557b055a8c        9 days ago          458MB
pweb_joomla                     latest              22c6d70d575e        10 days ago         1.01GB
fweb_joomla                     latest              0e36548560af        11 days ago         2.47GB
joomla                          apache              73acf8852f1b        13 days ago         461MB
mysql                           5.6                 732765f8c7d2        4 weeks ago         257MB
joomla                          3.9.5-apache        398227376f4a        4 months ago        415MB
alterway/php                    5.3-apache          87058120bc90        8 months ago        623MB
orsolin/docker-php-5.3-apache   latest              d8e72369c6e9        2 years ago         533MB
airinuit_mysql                  latest              fa73519d1891        2 years ago         304MB
vsamov/mysql-5.1.73             latest              fa73519d1891        2 years ago         304MB

您不想删除该守护程序,该守护程序实际上是 运行 在您的主机上使您能够执行 运行 docker 命令的软件。

如果你想删除现有的图像、卷、容器、网络、构建缓存,你可以深入了解命令

docker system prune

小心,它会删除很多你可能仍然会用到的东西。

如果你想确定在你的主机中需要 space 的是什么,在重新清理之前,你也可以 运行

$ docker system df

TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              5                   2                   16.43 MB            11.63 MB (70%)
Containers          2                   0                   212 B               212 B (100%)
Local Volumes       2                   1                   36 B                0 B (0%)

相关文档: https://docs.docker.com/engine/reference/commandline/system_df/

这可以在您的主机上回收大量 space,甚至可以为您提供它回收的 space 数量的总和:

$ docker system prune

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y

Deleted Containers:
f44f9b81948b3919590d5f79a680d8378f1139b41952e219830a33027c80c867
792776e68ac9d75bce4092bc1b5cc17b779bc926ab04f4185aec9bf1c0d4641f

Deleted Networks:
network1
network2

Deleted Images:
untagged: hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
deleted: sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57
deleted: sha256:45761469c965421a92a69cc50e92c01e0cfa94fe026cdd1233445ea00e96289a

Total reclaimed space: 1.84kB

最激进的形式是:

$ docker system prune --all --volumes

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all volumes not used by at least one container
        - all images without at least one container associated to them
        - all build cache
Are you sure you want to continue? [y/N] y

Deleted Containers:
0998aa37185a1a7036b0e12cf1ac1b6442dcfa30a5c9650a42ed5010046f195b
73958bfb884fa81fa4cc6baf61055667e940ea2357b4036acbbe25a60f442a4d

Deleted Networks:
my-network-a
my-network-b

Deleted Volumes:
named-vol

Deleted Images:
untagged: my-curl:latest
deleted: sha256:7d88582121f2a29031d92017754d62a0d1a215c97e8f0106c586546e7404447d
deleted: sha256:dd14a93d83593d4024152f85d7c63f76aaa4e73e228377ba1d130ef5149f4d8b
untagged: alpine:3.3
deleted: sha256:695f3d04125db3266d4ab7bbb3c6b23aa4293923e762aa2562c54f49a28f009f
untagged: alpine:latest
deleted: sha256:ee4603260daafe1a8c2f3b78fd760922918ab2441cbb2853ed5c439e59c52f96
deleted: sha256:9007f5987db353ec398a223bc5a135c5a9601798ba20a1abba537ea2f8ac765f
deleted: sha256:71fa90c8f04769c9721459d5aa0936db640b92c8c91c9b589b54abd412d120ab
deleted: sha256:bb1c3357b3c30ece26e6604aea7d2ec0ace4166ff34c3616701279c22444c0f3
untagged: my-jq:latest
deleted: sha256:6e66d724542af9bc4c4abf4a909791d7260b6d0110d8e220708b09e4ee1322e1
deleted: sha256:07b3fa89d4b17009eb3988dfc592c7d30ab3ba52d2007832dffcf6d40e3eda7f
deleted: sha256:3a88a5c81eb5c283e72db2dbc6d65cbfd8e80b6c89bb6e714cfaaa0eed99c548

Total reclaimed space: 13.5 MB

可在此处找到文档: https://docs.docker.com/engine/reference/commandline/system_prune/

Docker 内部 运行 在 client/server 架构上。特别是,当您 运行 docker build 时,它会在您指定的目录中创建一个 tar 文件,并通过套接字将该 tar 文件发送到 Docker 守护程序, 并在那里解压它。 (即使在完全本地的系统上也是如此。)

如果出现问题,该内容可以在 /var/lib/docker/tmp 中备份。通常你根本不应该在 /var/lib/docker 中四处寻找,但清理这个目录应该是安全的。考虑在执行此操作时停止守护进程。停止守护进程,删除所有 /var/lib/docker,并恢复 tar 守护进程也应该有所帮助(您需要重新 docker build and/or docker pull 图像和重新 运行 容器,这将丢失您尚未备份的命名卷中的任何内容。

7.039 GB 的构建上下文非常大。除了这样的问题,它只会导致 docker build 步骤非常慢;如果所有这些内容都被 COPY 编辑到图像中,您可能会在尝试 docker push 构建图像时遇到类似的问题。您可以尝试清理诸如日志文件或堆转储之类的东西(如果它们被遗弃);将 .git 目录或本地供应商树之类的内容添加到 .dockerignore 文件也有助于减小上下文的大小。