【问题标题】:undo apt-get update (in docker container)撤消 apt-get 更新(在 docker 容器中)
【发布时间】:2020-01-17 18:21:23
【问题描述】:

我正在使用 docker,并希望通过在 ubuntu 映像顶部的 zip 文件中安装应用程序来创建一个最小的新层。 ubuntu 镜像既没有安装 wget 也没有安装 unzip,所以我使用 apt-get 安装它们,这需要一个 apt-get update 首先

docker run -it --name app_container ubuntu:latest
# now i have terminal access to the fresh app_container

# install wget and unzip
apt-get update
apt-get install wget -y
apt-get install unzip -y

# download and unpack the app
# ...

# remove wget and unzip
apt-get purge unzip
apt-get purge wget
# i need to remove some dependencies of wget that are no longer needed
apt-get autoremove

此时,如果新 docker 层的唯一内容是新应用程序,那就太好了,但仍然有 apt-get update 创建/更新的文件。我尝试使用删除那些

apt-get clean

不过一个

docker diff app_container

揭示了那里留下了许多更改的文件(不属于应用程序)。好的,所以这些大小可以忽略不计(主要是 /etc/ssl/var/lib/dpkg/info 中的一些残留 wget 证书以及 /var/lib/app/lists 中的 23MB 存档文件),但本着尽可能干净的 docker 层的精神:是否有一种聪明的方法来删除那些也是? ('聪明'的意思是不诉诸蛮力rm)

【问题讨论】:

  • 尝试使用apt-get install --no-install-recommends安装
  • - 最小化 docker 图像链接会导致从 /var/lib/app/lists 中删除所有内容,这似乎是 as-good-as-it-gets。
  • @user2915097 使用--no-install-recommends 的想法会在没有证书验证的情况下安装wget,因此我们必须将wget 与--no-check-certificate 选项一起使用。这是可行的,但并不值得,--no-install-recommends 似乎修改了与我的初始版本一样多的文件,使用apt get autoremove 删除 wget 的依赖项。

标签: docker apt-get


【解决方案1】:

apt-get update 的使用要与rm -rf /var/lib/apt/lists/* 同层配对使用。

使用此在线工具进行一些优化和清晰度检查: https://www.fromlatest.io/

【讨论】:

    【解决方案2】:

    似乎没有比删除 /var/lib/app/lists 中的所有内容更好的建议

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多