压缩 Docker 图像以使其变小
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:
…
Download the latest version:
$ 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:
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
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
MIT
暂无开放 Issues,或尚未同步最近议题。