If you’ve ever worked with Raspberry Pi projects, you know how quickly .img
files can balloon in size. Whether you’re archiving, sharing, or deploying your images, trimming them down is crucial. That’s where PiShrink comes in — a handy script that automatically shrinks and optimizes Raspberry Pi OS images.
But what if you’re on macOS or Windows, and you don’t have a Linux system set up? Traditionally, you’d be out of luck — PiShrink requires Linux tools like losetup
, e2fsck
, and resize2fs
, which aren’t natively available on those platforms.
To solve this, we built a lightweight Docker-based wrapper for PiShrink that makes it easy to shrink and compress .img
files on any system with Docker installed — no full Linux environment required.
Runs Anywhere: Works on macOS, Windows, and Linux via Docker.
No Setup Hassle: No need to install resize tools or manage dependencies.
Supports Compression: Optional xz
compression reduces image sizes even further.
Safe and Isolated: Runs in a disposable container using Docker’s --rm
flag.
We built a Docker image that bundles all dependencies and runs the official PiShrink script. You can run it via our wrapper script, or directly with docker run
. It supports both in-place shrinking and compressed output.
docker run --rm --privileged -v /dev:/dev -v "$PWD:/data" pishrink image.img
docker run --rm --privileged -v /dev:/dev -v "${PWD}:/data" pishrink image.img
docker run --rm --privileged -v /dev:/dev -v "%cd%:/data" pishrink image.img
docker run --rm --privileged -v /dev:/dev -v "$PWD:/data" pishrink -Z -a image.img
This will produce image.img.xz
in the same directory, ready to store or share.
Visit the GitHub repo for full setup instructions and usage examples:
👉 https://github.com/keyqcloud/pishrink-docker
Whether you're managing headless Pi setups, building IoT devices, or just like your .img
files neat and tidy, this tool saves time and space.
Need help using this in a build pipeline or automated deployment process? Contact us at KeyQ — we love optimizing developer workflows.