Shrink Raspberry Pi Images Easily with Docker
Read Time 2 mins | Written by: Kenneth Hough

Shrink Raspberry Pi Images Easily with Docker
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.
Key Benefits
-
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.
How It Works
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.
Example (macOS/Linux):
docker run --rm --privileged -v /dev:/dev -v "$PWD:/data" pishrink image.img
PowerShell (Windows):
docker run --rm --privileged -v /dev:/dev -v "${PWD}:/data" pishrink image.img
Command Prompt (Windows):
docker run --rm --privileged -v /dev:/dev -v "%cd%:/data" pishrink image.img
With compression:
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.
Get Started
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.
A Framework Built to Accelerate App Development for Startups
Kenneth Hough
Background
I founded KeyQ in March of 2020 with the vision of helping businesses achieve the next level of success through delivering innovative and meaningful cloud solutions. Since its inception, I have worked with several businesses, non-profit organizations, and universities to design and build cloud applications that have helped streamline their business processes and reduce costs.
Prior to KeyQ, I was a medical researcher at the University of Alabama at Birmingham (UAB) in the Division of Pulmonary, Allergy, and Critical Care Medicine. UAB is also where I worked on my doctoral thesis under the mentorship of Dr. Jessy Deshane and Dr. Victor Thannickal. During my doctoral work at UAB I was exposed to the “omics” and big data, which has influenced my career choice to develop data-driven analytics platforms in the cloud.
I also have to give a big shoutout to my undergraduate education at Worcester Polytechnic Institute (WPI), where I majored in biochemistry. WPI’s motto is “Lehr und Kunst,” which roughly translates to “Theory and Practice” or “Learning and Skilled Art.” WPI truly cherishes and upholds this pedagogy, which can be seen by the teaching styles and class sizes. The learning experience I had at WPI is unique and has shaped me to be who I am, being able to learn, practice and apply.
Personal Interests
I love to learn innovative technologies and try new things. I have a broad area of interests that include serverless architectures, machine learning, artificial intelligence, bioinformatics, medical informatics, and financial technology. I am also working towards my CFA level 1 exam for 2021. Other interests and hobbies include traveling, rock climbing, rappelling, caving, camping and gardening!