A lightweight Docker-based tool for shrinking and optionally compressing Raspberry Pi .img files using PiShrink.
This wrapper allows you to shrink and compress Raspberry Pi OS images without needing to install Linux tools directly on your macOS or Windows system.
- On macOS and Windows, Docker Desktop uses a virtualized Linux kernel. The
--privilegedand/dev:/devmount allow access to loop devices required by PiShrink. - This is not recommended for general-purpose containers, but safe for this one-off tool.
run-pishrink.sh— CLI wrapper for shrinking/compressing.imgfiles (see usage)
- Docker installed
-
Clone this repo or copy the
Dockerfileandrun-pishrink.shscript to your working directory. -
Build the Docker image:
docker build -t pishrink ../run-pishrink.sh path/to/image.imgThis runs PiShrink and modifies the image in-place.
./run-pishrink.sh path/to/image.img --xzThis runs PiShrink and compresses the output with xz. The result will be:
image.img.xz
You can also run PiShrink directly using docker run:
Linux/macOS
docker run --rm --privileged -v /dev:/dev -v "$PWD:/data" pishrink image.imgWindows
docker run --rm --privileged -v /dev:/dev -v "${PWD}:/data" pishrink image.imgLinux/macOS
docker run --rm --privileged -v /dev:/dev -v "$PWD:/data" pishrink -Z -a image.imgWindows
docker run --rm --privileged -v /dev:/dev -v "${PWD}:/data" pishrink -Z -a image.imgThis will shrink and compress the image using xz with multithreading. The output will be image.img.xz in the same directory.
| Input | Command | Output File |
|---|---|---|
raspbian.img |
./run-pishrink.sh raspbian.img |
raspbian.img (shrunk) |
raspbian.img |
./run-pishrink.sh raspbian.img --xz |
raspbian.img.xz |
- This wrapper runs PiShrink in a one-off container (
docker run --rm) and mounts your current directory for in-place processing. - The Docker image pulls the latest PiShrink script at build time, so there's no need to check for updates at runtime.
Dockerfile— builds a lightweight Debian image with PiShrink installedrun-pishrink.sh— CLI wrapper for shrinking and compressing.imgfiles
To remove the built Docker image:
docker rmi pishrink