Skip to content

Latest commit

Β 

History

History
105 lines (67 loc) Β· 2.97 KB

File metadata and controls

105 lines (67 loc) Β· 2.97 KB

PiShrink Docker Wrapper

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 --privileged and /dev:/dev mount 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 .img files (see usage)

πŸ›  Requirements

πŸš€ Setup

  1. Clone this repo or copy the Dockerfile and run-pishrink.sh script to your working directory.

  2. Build the Docker image:

   docker build -t pishrink .

πŸ”§ Usage

πŸ”Ή Shrink only (no compression)

./run-pishrink.sh path/to/image.img

This runs PiShrink and modifies the image in-place.

πŸ”Ή Shrink and compress with xz

./run-pishrink.sh path/to/image.img --xz

This runs PiShrink and compresses the output with xz. The result will be:

image.img.xz

πŸ“‹ Direct Docker usage (without wrapper script)

You can also run PiShrink directly using docker run:

Shrink only (no compression):

Linux/macOS

docker run --rm --privileged -v /dev:/dev -v "$PWD:/data" pishrink image.img

Windows

docker run --rm --privileged -v /dev:/dev -v "${PWD}:/data" pishrink image.img

Shrink and compress with xz:

Linux/macOS

docker run --rm --privileged -v /dev:/dev -v "$PWD:/data" pishrink -Z -a image.img

Windows

docker run --rm --privileged -v /dev:/dev -v "${PWD}:/data" pishrink -Z -a  image.img

This will shrink and compress the image using xz with multithreading. The output will be image.img.xz in the same directory.

πŸ“† Output Example

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

πŸ“ Notes

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

πŸ“‚ Files Included

  • Dockerfile β€” builds a lightweight Debian image with PiShrink installed
  • run-pishrink.sh β€” CLI wrapper for shrinking and compressing .img files

🧼 Optional Cleanup

To remove the built Docker image:

docker rmi pishrink

πŸ™Œ Credits