docker-reclaim-disk-space
docker-reclaim-disk-space copied to clipboard
Script fails with "mnt: Invalid argument" on bigsur (x64 mode)
Hi, When I try to run the script, I get this:
docker run --privileged --pid=host docker/desktop-reclaim-space
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
setns:mnt: Invalid argument
Would you be able to help or point out to where the problem may lie? Thanks
The root cause is that "docker/docker-reclaim-space" image is build specifically for "linux/amd64" platform architecture. And you're running on newer Apple laptop with M1 chip, based on ARM architecture.
Normally, Docker is able to detect the architecture of your host machine, and pull the correct image, but "docker/docker-reclaim-space" image has only one variant. https://hub.docker.com/r/docker/desktop-reclaim-space/tags?page=1&ordering=last_updated
From: Docker Desktop for Apple silicon | Docker Documentation https://docs.docker.com/desktop/mac/apple-silicon/
Not all images are available for ARM64 architecture. You can add --platform linux/amd64 to run an Intel image under emulation. In particular, the mysql image is not available for ARM64. You can work around this issue by using a mariadb image.
However, attempts to run Intel-based containers on Apple Silicon machines under emulation can crash as qemu sometimes fails to run the container. In addition, filesystem change notification APIs (inotify) do not work under qemu emulation. Even when the containers do run correctly under emulation, they will be slower and use more memory than the native equivalent.
In summary, running Intel-based containers on Arm-based machines should be regarded as “best effort” only. We recommend running arm64 containers on Apple Silicon machines whenever possible, and encouraging container authors to produce arm64, or multi-arch, versions of their containers. We expect this issue to become less common over time, as more and more images are rebuilt supporting multiple architectures.
So the quick workaround to test from your side is to use "linux/amd64" image and run it under emulation by adding --platform linux/amd64
. It might or might not work.
docker run --privileged --pid=host --platform linux/amd64 docker/desktop-reclaim-space
From my side, seems like I need to add extra check for the ARM achitecture of the host machine and don't even try running "docker/docker-reclaim-space". Something like this:
if [ "$(uname)" == "Darwin" ] && is_intel_chip; then
echo "👉 Shrink the Docker.raw file"
docker run --privileged --pid=host docker/desktop-reclaim-space
fi
Alternative solution would be building using some image with "nsenter" prebuild (like debian), and then run "fstrim" manually in the same way as docker/desktop-reclaim-space
does under the hood.
ENTRYPOINT ["/usr/bin/nsenter1" "/sbin/fstrim" "/var/lib/docker"]
Something like this (not sure, just an idea). Since debian
image is built for different architectures including ARM, it should work.
docker run -it --privileged --pid=host debian nsenter fstrim /var/lib/docker
Will mark it as a defect.
Oh, GH automatically closes the issue after the quick fix commit.
I added a quick fix to run docker/desktop-reclaim-space
only on Intel chips. But will find another solution to support ARM chips as well, so I will leave this issue in "Opened" state.
But, at least, script will not be failing on you machine. @joaocc
Hi. Thx. Btw, the image does run on my machine (I am still on a everything-x64 even on M1) but it fails.
I am still getting the invalid argument error after running the command with the platform flag, though the warning message has gone away.
docker run --rm --privileged --pid=host --platform linux/amd64 docker/desktop-reclaim-space
setns:mnt: Invalid argument
I am using OS Monterey on the 2021 Macbook with the M1 chip. I have also tried the platform linux/x86_64
I am on the M1 but all images fail for me too.
@samoshkin same here ...
same here on M1
Same here also on M1
Same here also on M1
Same here
As workaround on my Mac M1:
- docker run -it --rm --privileged --pid=host justincormack/nsenter1
- fstrim /var/lib/docker
- exit
Any progress on this issue? Can't find any way to shrink it
docker run -it --rm --privileged --pid=host justincormack/nsenter1
fstrim /var/lib/docker
exit
I tried that but it doesn't seem to work, i.e. disk image size hasn't been reduced.
It would be awesome if original docker run --privileged --pid=host docker/desktop-reclaim-space
would work on M1... Running into "no space left on disk" when trying to run something is quite annoying...
same issue on mac m1