Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

docker-squash

> 编程语言
Open source

Squash docker images to make them smaller

2.0K stars0 likes1 views
WebsiteGitHub

About

Squash docker images to make them smaller

This is project is no longer under development

docker-squash

Squash docker images to make them smaller.

docker-squash is a utility to squash multiple docker layers into one in order to create an image with fewer and smaller layers. It retains Dockerfile commands such as PORT, ENV, etc.. so that squashed images work the same as they were originally built. In addition, deleted files in later layers are actually purged from the image when squashed.

It's designed to support a workflow where you would squash the image just before pushing it to a registry. Before squashing the image, you would remove any build time dependencies, extra files (apt caches, logs, private keys, etc..) that you would not want to deploy. The defaults also preserve your base image so that its contents are not repeatedly transferred when pushing and pulling images.

Typical workflow is:

  • Build image from Dockerfile (or other)
  • Run clean up commands in container (apt-get purge, rm /path, etc..)
  • Commit container
  • Squash the image
  • Push squashed image to registry

See Squashing Docker Images

Sample Output

…

Installation

Download the latest version:

  • Linux linux/amd64
  • OSX darwin/amd64
$ wget https://github.com/jwilder/docker-squash/releases/download/v0.2.0/docker-squash-linux-amd64-v0.2.0.tar.gz
$ sudo tar -C /usr/local/bin -xzvf docker-squash-linux-amd64-v0.2.0.tar.gz

NOTE: docker-squash must run as root (to maintain file permission created within images).

Dependencies:

  • tar 1.27

Usage

docker-squash works by squashing a saved image and loading the squashed image back into docker.

$ docker save <image id> > image.tar
$ sudo docker-squash -i image.tar -o squashed.tar
$ cat squashed.tar | docker load
$ docker images <new image id>

You can also tag the squashed image:

$ docker save <image id> > image.tar
$ sudo docker-squash -i image.tar -o squashed.tar -t newtag
$ cat squashed.tar | docker load
$ docker images <new image id>

You can reduce disk IO by piping the input and output to and from docker:

$ docker save <image id> | sudo docker-squash -t newtag | docker load

If you have a sufficient amount of RAM, you can also use a tmpfs to remove temporary disk storage:

$ docker save <image_id> | sudo TMPDIR=/var/run/shm docker-squash -t newtag | docker load

By default, a squashed layer is inserted after the first FROM layer. You can specify a different layer with the -from argument.

$ docker save <image_id> | sudo docker-squash -from <other layer> -t newtag | docker load

If you are creating a base image or only want one final squashed layer, you can use the -from root to squash the base layer and your changes into one layer.

$ docker save <image_id> | sudo docker-squash -from root -t newtag | docker load

Development

This project uses glock for managing 3rd party dependencies. You'll need to install glock into your workspace before hacking on docker-squash.

$ git clone <your fork>
$ glock sync github.com/jwilder/docker-squash
$ make

License

MIT

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言