如何展平 Docker 镜像? [英] How to flatten a Docker image?

查看:36
本文介绍了如何展平 Docker 镜像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个相当大的 Docker 容器.当我提交容器以创建映像时,映像大小约为 7.8 GB.但是当我export容器(不是save图像!)到一个tarball并重新导入它时,图像只有3 GB大.当然历史丢失了,但这对我来说没问题,因为在我看来图像已经完成"并准备部署.

I made a Docker container which is fairly large. When I commit the container to create an image, the image is about 7.8 GB big. But when I export the container (not save the image!) to a tarball and re-import it, the image is only 3 GB big. Of course the history is lost, but this OK for me, since the image is "done" in my opinion and ready for deployment.

如何在不将图像/容器导出到磁盘并再次导入的情况下展平图像/容器?并且:这样做是一个明智的主意还是我遗漏了一些重要的点?

推荐答案

从 Docker 1.13 开始,您可以使用 --squash 标志.

Up from Docker 1.13, you can use the --squash flag.

1.13 版之前:

据我所知,您不能使用 Docker api.docker exportdocker import 就是为这个场景设计的,正如你自己已经提到的.

To my knowledge, you cannot using the Docker api. docker export and docker import are designed for this scenario, as you yourself already mention.

如果您不想保存到磁盘,您可以将导出的输出流通过管道传输到导入的输入流中.我还没有测试过这个,但试试

If you don't want to save to disk, you could probably pipe the outputstream of export into the input stream of import. I have not tested this, but try

docker export red_panda | docker import - exampleimagelocal:new

这篇关于如何展平 Docker 镜像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆