docker-reclaim-disk-space icon indicating copy to clipboard operation
docker-reclaim-disk-space copied to clipboard

Script fails with "mnt: Invalid argument" on bigsur (x64 mode)

Open joaocc opened this issue 3 years ago • 14 comments

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

joaocc avatar Sep 18 '21 12:09 joaocc

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.

samoshkin avatar Sep 18 '21 12:09 samoshkin

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

samoshkin avatar Sep 18 '21 12:09 samoshkin

Hi. Thx. Btw, the image does run on my machine (I am still on a everything-x64 even on M1) but it fails.

joaocc avatar Sep 18 '21 14:09 joaocc

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

rolandgill avatar Jan 03 '22 18:01 rolandgill

I am on the M1 but all images fail for me too.

jwh-hutchison avatar Jan 31 '22 15:01 jwh-hutchison

@samoshkin same here ...

rene-mueller avatar Feb 21 '22 11:02 rene-mueller

same here on M1

vaibhavkumar-sf avatar Feb 23 '22 11:02 vaibhavkumar-sf

Same here also on M1

kateharwood avatar Mar 30 '22 16:03 kateharwood

Same here also on M1

27149chen avatar Apr 06 '22 01:04 27149chen

Same here

lucidlive avatar Jun 03 '22 13:06 lucidlive

As workaround on my Mac M1:

  1. docker run -it --rm --privileged --pid=host justincormack/nsenter1
  2. fstrim /var/lib/docker
  3. exit

drwatson32 avatar Jun 29 '22 20:06 drwatson32

Any progress on this issue? Can't find any way to shrink it

jonas-db avatar Jul 06 '22 08:07 jonas-db

  • 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...

woj-tek avatar Sep 21 '22 06:09 woj-tek

same issue on mac m1

badgerdf avatar Feb 22 '23 09:02 badgerdf