[英]Docker error : no space left on device
I installed docker on a Debian 7 machine in the following way我通过以下方式在 Debian 7 机器上安装了 docker
$ echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list
$ sudo apt-get update
$ curl -sSL https://get.docker.com/ubuntu/ | sudo sh
After that when I first tried creating an Image it failed with the following error之后,当我第一次尝试创建图像时,它失败并出现以下错误
time="2015-06-02T14:26:37-04:00" level=info msg="[8] System error: write /sys/fs/cgroup/docker/01f5670fbee1f6687f58f3a943b1e1bdaec2630197fa4da1b19cc3db7e3d3883/cgroup.procs: no space left on device"
Here is the docker info这是码头信息
Containers: 2
Images: 21
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 25
Dirperm1 Supported: true
Execution Driver: native-0.2
Kernel Version: 3.16.0-0.bpo.4-amd64
Operating System: Debian GNU/Linux 7 (wheezy)
CPUs: 2
Total Memory: 15.7 GiB
WARNING: No memory limit support
WARNING: No swap limit support
How can I increase the memory?如何增加内存? Where are the system configurations stored?
系统配置存储在哪里?
From Kal's suggestions:来自 Kal 的建议:
When I got rid of all the images and containers it did free some space and the image build ran longer before failing with the same error.当我删除所有图像和容器时,它确实释放了一些空间,并且图像构建运行时间更长,然后失败并出现相同的错误。 So the question is, which space is this referring to and how do I configure it?
所以问题是,这是指哪个空间以及如何配置它?
The current best practice is:当前的最佳实践是:
docker system prune
Note the output from this command prior to accepting the consequences:在接受后果之前,请注意此命令的输出:
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N]
In other words, continuing with this command is permanent.换句话说,继续执行此命令是永久性的。 Keep in mind that best practice is to treat stopped containers as ephemeral ie you should be designing your work with Docker to not keep these stopped containers around.
请记住,最佳实践是将停止的容器视为短暂的,即您应该使用 Docker 设计您的工作,而不是保留这些停止的容器。 You may want to consider using the
--rm
flag at runtime if you are not actively debugging your containers.如果您不主动调试容器,您可能需要考虑在运行时使用
--rm
标志。
Make sure you read this answer , re: Volumes确保你阅读了这个答案,re:Volumes
You may also be interested in this answer , if docker system prune
does not work for you.如果
docker system prune
对您不起作用,您可能也对这个答案感兴趣。
I had the same error and solve it this way:我有同样的错误并通过这种方式解决它:
1 . 1 . Delete the orphaned volumes in Docker, you can use the built-in docker volume command.
删除 Docker 中的孤立卷,可以使用内置的 docker volume 命令。 The built-in command also deletes any directory in /var/lib/docker/volumes that is not a volume so make sure you didn't put anything in there you want to save.
内置命令还会删除 /var/lib/docker/volumes 中不是卷的任何目录,因此请确保没有在其中放置任何要保存的内容。
Warning be very careful with this if you have some data you want to keep警告如果您有一些要保留的数据,请务必小心
Cleanup:清理:
$ docker volume rm $(docker volume ls -qf dangling=true)
Additional commands:附加命令:
List dangling volumes:列出悬空卷:
$ docker volume ls -qf dangling=true
List all volumes:列出所有卷:
$ docker volume ls
2 . 2 . Also consider removing all the unused Images.
还要考虑删除所有未使用的图像。
First get rid of the <none>
images (those are sometimes generated while building an image and if for any reason the image building was interrupted, they stay there).首先去掉
<none>
图像(这些图像有时是在构建图像时生成的,如果由于任何原因图像构建被中断,它们会留在那里)。
here's a nice script I use to remove them这是我用来删除它们的一个很好的脚本
docker rmi $(docker images | grep '^<none>' | awk '{print $3}')
Then if you are using Docker Compose to build Images locally for every project.然后,如果您使用 Docker Compose 为每个项目在本地构建图像。 You will end up with a lot of images usually named like your folder (example if your project folder named Hello, you will find images name
Hello_blablabla
).您最终会得到很多通常以您的文件夹命名的图像(例如,如果您的项目文件夹名为 Hello,您会发现图像名称为
Hello_blablabla
)。 so also consider removing all these images所以还要考虑删除所有这些图像
you can edit the above script to remove them or remove them manually with您可以编辑上述脚本以删除它们或手动删除它们
docker rmi {image-name}
Check that you have free space on /var as this is where Docker stores the image files by default (in /var/lib/docker).检查 /var 上是否有可用空间,因为这是 Docker 默认存储图像文件的地方(在 /var/lib/docker 中)。
First clean stuff up by using docker ps -a
to list all containers (including stopped ones) and docker rm
to remove them;首先使用
docker ps -a
列出所有容器(包括停止的容器)并使用docker rm
删除它们来清理内容; then use docker images
to list all the images you have stored and docker rmi
to remove them.然后使用
docker images
列出您存储的所有图像并使用docker rmi
删除它们。
Next change the storage location with a -g option on the docker daemon or by editing /etc/default/docker
and adding the -g
option to DOCKER_OPTS
.接下来使用 docker 守护进程上的 -g 选项或通过编辑
/etc/default/docker
DOCKER_OPTS
并将-g
选项添加到DOCKER_OPTS
来更改存储位置。 -g
specifies the location of the "Docker runtime" which is basically all the stuff that Docker creates as you build images and run containers. -g
指定“Docker 运行时”的位置,它基本上是 Docker 在您构建映像和运行容器时创建的所有内容。 Choose a location with plenty of space as the disk space used will tend to grow over time.选择一个有足够空间的位置,因为使用的磁盘空间会随着时间的推移而增长。 If you edit
/etc/default/docker
, you will need to restart the docker daemon for the change to take effect.如果编辑
/etc/default/docker
,则需要重新启动 docker 守护进程以使更改生效。
Now you should be able to create a new image (or pull one from Docker Hub) and you should see a bunch of files getting created in the directory you specified with the -g option.现在您应该能够创建一个新镜像(或从 Docker Hub 中拉取一个),并且您应该会看到在您使用 -g 选项指定的目录中创建了一堆文件。
As already mentioned,如前所述,
docker system prune
helps, but with Docker 17.06.1 and later without pruning unused volumes.有帮助,但使用 Docker 17.06.1 及更高版本,无需修剪未使用的卷。 Since Docker 17.06.1, the following command prunes volumes, too:
从 Docker 17.06.1 开始,以下命令也会修剪卷:
docker system prune --volumes
From the Docker documentation: https://docs.docker.com/config/pruning/来自 Docker 文档: https : //docs.docker.com/config/pruning/
The docker system prune command is a shortcut that prunes images, containers, and networks.
docker system prune 命令是一种修剪镜像、容器和网络的快捷方式。 In Docker 17.06.0 and earlier, volumes are also pruned.
在 Docker 17.06.0 及更早版本中,卷也会被修剪。 In Docker 17.06.1 and higher, you must specify the --volumes flag for docker system prune to prune volumes.
在 Docker 17.06.1 及更高版本中,您必须为 docker system prune 指定 --volumes 标志以修剪卷。
If you want to prune volumes and keep images and containers:如果要修剪卷并保留图像和容器:
docker volume prune
So docker system prune
and docker system prune --volumes
suggested in other answers freed up some space each time, but eventually every time I ran anything I was getting the error.所以
docker system prune --volumes
docker system prune
和docker system prune --volumes
在其他答案中建议每次都释放一些空间,但最终每次我运行任何东西时都会出现错误。
What actually fixed the root issue was deleting the Docker.raw
file that Docker for Mac uses for storage, and restarting it.真正解决根本问题的是删除 Docker for Mac 用于存储的
Docker.raw
文件,然后重新启动它。
To find that file open up Docker for Mac and go to*要找到该文件,请打开 Docker for Mac 并转到*
Preferences > Resources > Advanced > Disk Image Location
*this is for version 2.2.0.5, but on older versions it should be similar
*这适用于 2.2.0.5 版,但在旧版本上应该类似
On newer versions of Docker for Mac**, it shows you the actual size of that file on disk right there in the UI, as well as its max allocated size.在较新版本的 Docker for Mac** 上,它会在 UI 中显示磁盘上该文件的实际大小,以及其最大分配大小。 You'll probably see that it is massive.
你可能会看到它是巨大的。 For example on my machine it was 41GB !
例如在我的机器上它是41GB !
**On older versions, it doesn't show you the actual disk usage in the UI, and MacOS Finder always shows the file size as the max allocated size.
**在旧版本中,它不会在 UI 中显示实际磁盘使用情况,MacOS Finder始终将文件大小显示为最大分配大小。 You can check the actual size on disk by opening the directory in a terminal and running
du -h Docker.raw
您可以通过在终端中打开目录并运行
du -h Docker.raw
来检查磁盘上的实际大小
I deleted Docker.raw
, restarted Docker for Mac, and the file was automatically created again and was back to being 0GB .我删除了
Docker.raw
,为 Mac 重新启动了 Docker,然后该文件又自动创建并恢复为0GB 。
Everything continued to work as before , though of course I had lost my Docker cache.一切都像以前一样继续工作,当然我丢失了我的 Docker 缓存。 As expected, after running a few Docker commands the file started to fill up again with a few GB of stuff, but nowhere near 41GB.
正如预期的那样,在运行了一些 Docker 命令后,文件开始再次填满几 GB 的内容,但还不到41 GB。
Update更新
A few months later, my Docker.raw
filled back up again to a similar size.几个月后,我的
Docker.raw
再次填充到类似的大小。 So this method did work, but has to repeated every few months.所以这种方法确实有效,但必须每隔几个月重复一次。 For me that's fine.
对我来说很好。
A note on why this works - I have to assume it's a bug in Docker for Mac.关于为什么这样做的说明 - 我必须假设这是 Docker for Mac 中的一个错误。 It really seems like
docker system prune
/ docker system prune --volumes
should entirely clear the contents of this file, but it appears the file accumulates other stuff that can't be deleted by these commands.看起来
docker system prune --volumes
docker system prune
/ docker system prune --volumes
应该完全清除该文件的内容,但该文件似乎积累了这些命令无法删除的其他内容。 Anyway, deleting it manually solves the problem!无论如何,手动删除它可以解决问题!
If it's just a test installation of Docker (ie not production) and you don't care about doing a nuclear clean, you can:如果它只是 Docker 的测试安装(即不是生产)并且您不关心进行核清理,您可以:
clean all containers: docker ps -a | sed '1 d' | awk '{print $1}' | xargs -L1 docker rm
清理所有容器:
docker ps -a | sed '1 d' | awk '{print $1}' | xargs -L1 docker rm
docker ps -a | sed '1 d' | awk '{print $1}' | xargs -L1 docker rm
clean all images: docker images -a | sed '1 d' | awk '{print $3}' | xargs -L1 docker rmi -f
清理所有图像:
docker images -a | sed '1 d' | awk '{print $3}' | xargs -L1 docker rmi -f
docker images -a | sed '1 d' | awk '{print $3}' | xargs -L1 docker rmi -f
Again, I use this in my ec2 instances when developing Docker, not in any serious QA or Production path.同样,我在开发 Docker 时在我的 ec2 实例中使用它,而不是在任何严肃的 QA 或生产路径中。 The great thing is that if you have your Dockerfile(s), it's easy to rebuild and or
docker pull
.很棒的是,如果你有你的 Dockerfile(s),它很容易重建和/或
docker pull
。
to remove all unused containers, volumes, networks and images at once ( https://docs.docker.com/engine/reference/commandline/system_prune/#related-commands ):一次删除所有未使用的容器、卷、网络和图像( https://docs.docker.com/engine/reference/commandline/system_prune/#related-commands ):
docker system prune -a -f --volumes
if it's not enough, one can remove running containers first:如果这还不够,可以先删除正在运行的容器:
docker rm -f $(docker ps -a -q)
docker system prune -a -f --volumes
increasing /var/lib/docker or using another location with more space is also a good alternative to get rid of this error (see How to change the docker image installation directory? )增加 /var/lib/docker 或使用具有更多空间的其他位置也是摆脱此错误的不错选择(请参阅如何更改 docker 映像安装目录? )
Docker leaves dangling images around that can take up your space. Docker 会留下悬空的图像,这些图像会占用您的空间。 To clean up after Docker, run the following:
要在 Docker 之后进行清理,请运行以下命令:
docker image prune [-af if you want to force remove all images]
or with older versions of Docker:或使用旧版本的 Docker:
docker rm $(docker ps -q -f 'status=exited')
docker rmi $(docker images -q -f "dangling=true")
This will remove exited and dangling images, which hopefully clears out device space.这将删除退出和悬空的图像,这有望清除设备空间。
I also encountered this issue on RHEL machine.我在 RHEL 机器上也遇到过这个问题。 I did not find any apt solution anywhere on stack-overflow and docker-hub community.
我在 stack-overflow 和 docker-hub 社区的任何地方都没有找到任何合适的解决方案。 If you are facing this issue even after below command:
如果您在执行以下命令后仍面临此问题:
docker system prune --all docker system prune --all
The solution which worked finally:最终奏效的解决方案:
docker rmi $(docker images -f "dangling=true" -q)
docker rmi $(docker images -f "dangling=true" -q)
1. Remove Containers : 1. 移除容器:
$ docker rm $(docker ps -aq)
2. Remove Images : 2. 删除图像:
$ docker rmi $(docker images -q)
Instead of perform steps 1 and 2 you can do:您可以执行以下操作,而不是执行步骤 1 和 2:
docker system prune
This command will remove:此命令将删除:
you can also use:您还可以使用:
docker system prune
or for just volumes:或仅用于卷:
docker volume prune
In my case I didn't have so many images/containers, but the build cache was filling up my Docker Disk.就我而言,我没有那么多图像/容器,但构建缓存填满了我的 Docker 磁盘。
You can see that this is the problem by running您可以通过运行看到这是问题所在
docker system df
Output:输出:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 22 13 7.581GB 3.899GB (51%)
Containers 15 0 2.166GB 2.166GB (100%)
Local Volumes 4 4 550.2MB 0B (0%)
Build Cache 611 0 43.83GB 43.83GB!!!!!!!!!
The command below solves that issue下面的命令解决了这个问题
docker builder prune
If you already have clean the unused containers, images with如果您已经清理了未使用的容器,请使用
docker system prune -a
Make sure to check if you have unhealthy containers.确保检查您是否有不健康的容器。 They can act really in a weird and unpredictable way.
他们真的可以以一种奇怪和不可预测的方式行事。 In my case because of those, I got this error, even having tons of disk space.
在我的情况下,由于这些,我得到了这个错误,即使有大量的磁盘空间。
docker ps -a
will list all the containers. docker ps -a
将列出所有容器。 If any of them looks like this:如果其中任何一个看起来像这样:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds (unhealthy) 3300-3310/tcp webapp
You will need to restart the docker daemon.您将需要重新启动 docker 守护进程。
Clean Docker by using the following command:使用以下命令清理 Docker:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' \
| xargs docker rmi
In my case installation of ubuntu-server 18.04.1 [for some weird reason] created an LVM logical volume with just 4GBs in size instead of 750GBs.在我的情况下,安装 ubuntu-server 18.04.1 [出于某种奇怪的原因] 创建了一个大小仅为 4GB 而不是 750GB 的 LVM 逻辑卷。 Therefore when pulling images i would get this "no space left on device" error.
因此,在拉取图像时,我会收到“设备上没有剩余空间”错误。 The fix is simple:
修复很简单:
lvextend -l 100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
In my case, I ran the docker system df
to find out which component is consuming more space, and then I executed the docker system prune -a
to clean up all dangling containers, images, etc. Finally, I ran the docker volume rm $(docker volume ls -qf dangling=true)
to clean up the dangling volumes.在我的例子中,我运行了
docker system df
来找出哪个组件占用了更多的空间,然后我执行了docker system prune -a
来清理所有悬空的容器、图像等。最后,我运行了docker volume rm $(docker volume ls -qf dangling=true)
清理悬挂卷。
Below are the commands executed in order.下面是按顺序执行的命令。
docker system df
docker system prune -a
docker volume rm $(docker volume ls -qf dangling=true)
Don't just run the docker prune
command.不要只运行
docker prune
命令。 It will delete all the docker networks, containers, and images.它将删除所有 docker 网络、容器和图像。 So you might end up losing the important data as well.
因此,您最终也可能会丢失重要数据。
The error shows that "No space left on device" so we just need to free up some space.错误显示“设备上没有剩余空间”,所以我们只需要释放一些空间。
The easiest way to free some space is to remove dangling images.释放一些空间的最简单方法是删除悬空图像。
When the old created images are not being used those images are referred to as dangling images or there are some cache images as well which you can remove.当不使用旧创建的图像时,这些图像被称为悬空图像,或者还有一些缓存图像可以删除。
Use the below commands.使用以下命令。 To list all dangling images image id.
列出所有悬空图像图像 ID。
docker images -f "dangling=true" -q
to remove the images by image id.按图像 id 删除图像。
docker rmi IMAGE_ID
This way you can free up some space and start hacking with docker again :)这样你就可以释放一些空间并再次开始使用 docker 进行黑客攻击:)
Your cgroups have the cpuset
controller enabled.您的 cgroup 已启用
cpuset
控制器。 This controller is mostly useful in NUMA environment where it allows to finely specify which CPU/memory bank your tasks are allowed to run.该控制器在 NUMA 环境中最有用,它允许精细地指定允许您的任务运行的 CPU/内存组。
By default the mandatory cpuset.mems
and cpuset.cpus
are not set which means that there is "no space left" for your task, hence the error.默认情况下,未设置强制
cpuset.mems
和cpuset.cpus
,这意味着您的任务“没有剩余空间”,因此会出现错误。
The easiest way to fix this is to enable cgroup.clone_children
to 1 in the root cgroup.解决此问题的最简单方法是在根 cgroup 中启用
cgroup.clone_children
为 1。 In your case, it should be在你的情况下,它应该是
echo 1 > /sys/fs/cgroup/docker/cgroup.clone_children
It will basically instruct the system to automatically initialize container's cpuset.mems
and cpuset.cpus
from their parent cgroup.它基本上会指示系统从它们的父 cgroup 自动初始化容器的
cpuset.mems
和cpuset.cpus
。
If you're using the boot2docker image via Docker Toolkit, then the problem stems from the fact that the boot2docker virtual machine has run out of space.如果您通过 Docker Toolkit 使用 boot2docker 映像,则问题源于 boot2docker 虚拟机空间不足。
When you do a docker import
or add a new image, the image gets copied into the /mnt/sda1
which might have become full.当您执行
docker import
或添加新图像时,该图像会被复制到可能已满的/mnt/sda1
中。
One way to check what space you have available in the image, is to ssh into the vm and run df -h
and check the remaining space in /mnt/sda1检查映像中可用空间的一种方法是通过 ssh 进入 vm 并运行
df -h
并检查 /mnt/sda1 中的剩余空间
The ssh command is docker-machine ssh default
ssh 命令是
docker-machine ssh default
Once you are sure that it is indeed a space issue, you can either clean up according to the instructions in some of the answers on this question, or you may choose to resize the boot2docker image itself, by increasing the space on /mnt/sda1
一旦确定确实是空间问题,您可以根据此问题的某些答案中的说明进行清理,或者您可以选择通过增加
/mnt/sda1
上的空间来调整 boot2docker 映像本身的大小
You can follow the instructions here to do the resizing of the image https://gist.github.com/joost/a7cfa7b741d9d39c1307您可以按照此处的说明调整图像大小https://gist.github.com/joost/a7cfa7b741d9d39c1307
I run the below commands.我运行以下命令。
There is no need to rebuilt images afterwards.之后无需重建图像。
docker rm $(docker ps -qf 'status=exited')
docker rmi $(docker images -qf "dangling=true")
docker volume rm $(docker volume ls -qf dangling=true)
These remove exited/dangling containers and dangling volumes.这些删除退出/悬空容器和悬空卷。
Its may be due to the default storage space set to 40GB ( default path , /var/lib/docker)这可能是由于默认存储空间设置为 40GB(默认路径,/var/lib/docker)
you can change the storage volume to point to different path您可以更改存储卷以指向不同的路径
DOCKER_STORAGE_OPTIONS='--storage-driver=overlay --graph=CUSTOM_PATH' DOCKER_STORAGE_OPTIONS='--storage-driver=overlay --graph=CUSTOM_PATH'
if you run command docker info ( it should show storage driver as overlay)如果您运行命令 docker info (它应该将存储驱动程序显示为覆盖)
So many posts about prune statements.关于修剪语句的帖子太多了。 As it is true this command will clean up docker files, it does not fix your system if the actual storage is encumbered.
由于此命令确实会清理 docker 文件,因此如果实际存储受到阻碍,它不会修复您的系统。 For me the problem was the server's storage was just plain full.
对我来说,问题是服务器的存储空间已经满了。 Therefore I had two options.
因此我有两个选择。
Option 1: Clean up existing space选项 1:清理现有空间
df -H
, how much space is left? df -H
,还剩多少空间?du --block-size=M -a / | sort -n -r | head -n 20
du --block-size=M -a / | sort -n -r | head -n 20
检查什么占用了系统上这么多空间du --block-size=M -a / | sort -n -r | head -n 20
du --block-size=M -a / | sort -n -r | head -n 20
, that will show the 20 biggest files. du --block-size=M -a / | sort -n -r | head -n 20
,这将显示 20 个最大的文件。 Option 2: Get more space选项 2:获得更多空间
Seems like there are a few ways this can occur.似乎有几种方法可以发生这种情况。 The issue I had was that the docker disk image had hit its maximum size (Docker Whale -> Preferences -> Disk if you want to view what size that is in OSX).
我遇到的问题是 docker 磁盘映像已达到其最大大小(Docker Whale -> Preferences -> Disk 如果您想查看 OSX 中的大小)。
I upped the limit and and was good to go.我提高了限制并且很高兴去。 I'm sure cleaning up unused images would work as well.
我相信清理未使用的图像也会起作用。
For me docker system prune
did the trick.对我来说,
docker system prune
成功了。 I`m running mac os.我正在运行 mac os。
$ docker rm $(docker ps -aq)
This worked for me这对我有用
docker system prune
appears to be better option with latest version最新版本似乎是更好的选择
I just ran into this.我刚遇到这个。 I'm on Ubuntu 20.04.
我在 Ubuntu 20.04 上。 What worked?
什么工作? Reinstalling Docker:
重新安装 Docker:
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo apt-get install docker-ce docker-ce-cli containerd.io
A bit crude, I know.有点粗糙,我知道。 I tried pruning Docker, but it still would not work.
我尝试修剪 Docker,但它仍然不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.