百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

docker-squash

> 编程语言
开源

压缩 Docker 图像以使其变小

2.0K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

压缩 Docker 图像以使其变小

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Go

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

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