如何减小Vagrant VM镜像的大小

Tri*_*yen 1 vagrant centos6

我从这张图片https://atlas.hashicorp.com/bento/boxes/centos-6.7启动了一个虚拟机,大小只有2-300MB.然后我安装了一些软件包(java,node,docker等),以便为我的应用程序创建更快的起始图像.

我然后运行yum clean allvagrant package --output newimage.box,但是newimage.box是〜3GB大小.

我一直在寻找一种方法来压缩/缩小这个图像的大小,但没有找到很多.我发现了一些提到zerofree,但一直无法在CentOS盒子上安装它.

任何建议/建议将非常感激.

Fré*_*nri 5

您可以查看从packer中使用的清理脚本示例来缩小图像大小.

重点是

echo "==> Clean up yum cache of metadata and packages to save space"
yum -y --enablerepo='*' clean all

echo "==> Clear core files"
rm -f /core*

echo "==> Removing temporary files used to build box"
rm -rf /tmp/*

echo '==> Zeroing out empty area to save space in the final image'
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
Run Code Online (Sandbox Code Playgroud)