使用apt-get build deps最小化Docker图像 [英] Minimizing Docker Images with apt-get build deps

查看:365
本文介绍了使用apt-get build deps最小化Docker图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时在构建Docker图像时,需要使用 apt-get 。例如,运行Magento的图像可能会像这样开始

Sometimes when building Docker images it's necessary to use apt-get. For example, an image for running Magento might start something like this

FROM php:5.4-apache
RUN apt-get -qqy update \
 && apt-get -qqy install git \
                         libmcrypt-dev \
                         libpng12-dev \
                         libxml2-dev \
                         libxslt-dev \
 && docker-php-ext-install bcmath \
                           gd \
                           mcrypt \
                           mysql \
                           soap \
                           xsl \
                           zip

但是现在我已经把所有这些垃圾收集到这些 apt-get 命令。更糟糕的是,我甚至不确定我能负担得起什么,因为大概是PHP的动态链接。

But now I have all the junk brought in by those apt-get commands. Worse, I'm not even sure what I can afford to delete, because presumably the php libs are dynamically linked.

我正在考虑一些诸如


  1. 有没有办法静态链接 docker-php-ext-install ,所以我可以把所有的code> apt-get 东西?

  2. 如何删除 apt-get update

  1. Is there a way to statically link the php libs in docker-php-ext-install so I can nuke all the apt-get stuff?
  2. How can I remove the data left by apt-get update?

但这些确实只是 XY问题。我的实际问题只是

but those are really just X-Y questions. My actual question is just

如何构建较小的Docker图像,而不会完全消除使用的易用性和可维护性在Docker文件中apt-get

推荐答案

你可以摆脱一些东西一些东西通过运行 rm -rf / var / lib / apt / lists / * 例如

You can get rid of some stuff some stuff by running rm -rf /var/lib/apt/lists/* e.g.

RUN apt-get update \
    && apt-get install -y MY_PACKAGE \
    && rm -rf /var/lib/apt/lists/*

请记住,您需要运行此与 apt-get update 在同一行中有效。

Remember that you will need to run this in the same line as the apt-get update for it to be effective.

这篇关于使用apt-get build deps最小化Docker图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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