Docker:安装apt UTIL时遇到问题

Docker:安装apt UTIL时遇到问题,docker,apt,Docker,Apt,我试图在Docker上安装apt utils,因为当我刚刚执行apt get update时,我得到了错误:debconf:delaying package configuration,因为apt utils没有安装。因此,我添加了一行代码来安装apt-utils(以及curl): 但是,我仍然在犯错误,使我相信我的命令不起作用。下面是我尝试构建图像时的输出 Step 5/12 : RUN apt-get update && apt-get install -y apt-util

我试图在Docker上安装
apt utils
,因为当我刚刚执行
apt get update
时,我得到了错误:
debconf:delaying package configuration,因为apt utils没有安装
。因此,我添加了一行代码来安装
apt-utils
(以及
curl
):

但是,我仍然在犯错误,使我相信我的命令不起作用。下面是我尝试构建图像时的输出

Step 5/12 : RUN apt-get update && apt-get install -y apt-utils && apt-get install -y curl
 ---> Running in 6e6565ff01bd
Get:1 http://security.debian.org jessie/updates InRelease [94.4 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:3 http://deb.debian.org jessie Release.gpg [2420 B]
Get:4 http://deb.debian.org jessie Release [148 kB]
Get:5 http://security.debian.org jessie/updates/main amd64 Packages [624 kB]
Get:6 http://deb.debian.org jessie-updates/main amd64 Packages [23.0 kB]
Get:7 http://deb.debian.org jessie/main amd64 Packages [9098 kB]
Fetched 10.1 MB in 6s (1541 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  libapt-inst1.5
The following NEW packages will be installed:
  apt-utils libapt-inst1.5
0 upgraded, 2 newly installed, 0 to remove and 24 not upgraded.
Need to get 537 kB of archives.
After this operation, 1333 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian/ jessie/main libapt-inst1.5 amd64 1.0.9.8.4 [169 kB]
Get:2 http://deb.debian.org/debian/ jessie/main apt-utils amd64 1.0.9.8.4 [368 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 537 kB in 0s (557 kB/s)
Selecting previously unselected package libapt-inst1.5:amd64.
(Reading database ... 21676 files and directories currently installed.)
Preparing to unpack .../libapt-inst1.5_1.0.9.8.4_amd64.deb ...
Unpacking libapt-inst1.5:amd64 (1.0.9.8.4) ...
Selecting previously unselected package apt-utils.
Preparing to unpack .../apt-utils_1.0.9.8.4_amd64.deb ...
Unpacking apt-utils (1.0.9.8.4) ...
Setting up libapt-inst1.5:amd64 (1.0.9.8.4) ...
Setting up apt-utils (1.0.9.8.4) ...
Processing triggers for libc-bin (2.19-18+deb8u10) ...
Reading package lists...
Building dependency tree...
Reading state information...
curl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded.
Removing intermediate container 6e6565ff01bd
 ---> f65e29c6a6b9
Step 6/12 : RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
 ---> Running in f5764ba56103
Detected operating system as debian/8.
Checking for curl...
Detected curl...
Checking for gpg...
Detected gpg...
Running apt-get update... done.
Installing debian-archive-keyring which is needed for installing
apt-transport-https on many Debian systems.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/github_git-lfs.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.

The repository is setup! You can now install packages.
Removing intermediate container f5764ba56103
 ---> a4e64687ab73

这是什么原因造成的?我如何修复它?谢谢大家!

这实际上不是一个错误,可以安全地忽略它。我已经构建了大量的容器映像,但其中任何一个都没有apt-utils,而且不管这个警告消息如何,所有的包安装都能正常进行

无论如何,如果你想有apt utils,请安装它。它会给你这个警告一次,然后在以后调用apt-get时它就会消失(正如你在自己的日志中看到的,
curl
got installed没有这个消息)


注意:如果安装apt utils,您将收到其他警告(因为现在安装程序可以运行interactive config,并将尝试该操作,但失败)。要抑制这些,并使软件包具有默认的交互式配置,请像这样运行apt get
DEBIAN_FRONTEND=noninteractive apt get install-y pkgs…

在互联网上搜索后,我发现了一些值得一提的替代方案,而不是每次将
DEBIAN_FRONTEND=noninteractive
放在
apt get install-y{your pkgs}
前面:

备选方案1:ARG DEBIAN_FRONTEND=非交互式

ARG指令定义了一个用户可以传递的变量 使用docker build命令,使用 --build arg=flag。(参考文献:[])

解决方案特征:

  • ARG
    指令仅在生成期间设置
  • 选项“非交互”仅设置为构建时的默认值
  • 由于它是一个参数,因此可以通过为该参数传递另一个值来更改它,例如,
    docker build--build arg DEBIAN_FRONTEND=newt
例如:

ARG DEBIAN_FRONTEND=noninteractive
...
RUN apt-get -yq install {your-pkgs}
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install {your-pkgs}
# Set for all apt-get install, must be at the very beginning of the Dockerfile.
ENV DEBIAN_FRONTEND noninteractive
...
# Non-interactive modes get set back.
ENV DEBIAN_FRONTEND newt
# Set the frontend and then install your package
RUN export DEBIAN_FRONTEND=noninteractive && \
    ...
    apt-get -yq install {your-pkgs} && \
    ...
备选方案2:在运行中

这是Leo K.的解决方案

解决方案特征:

  • 它可以设置在需要的地方。因此,这是一个良好的细粒度解决方案
  • 它可以在特定命令中的不同值中设置,因此它不是全局设置的
  • 作用域是
    运行
    ,不会影响其他指令
例如:

ARG DEBIAN_FRONTEND=noninteractive
...
RUN apt-get -yq install {your-pkgs}
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install {your-pkgs}
# Set for all apt-get install, must be at the very beginning of the Dockerfile.
ENV DEBIAN_FRONTEND noninteractive
...
# Non-interactive modes get set back.
ENV DEBIAN_FRONTEND newt
# Set the frontend and then install your package
RUN export DEBIAN_FRONTEND=noninteractive && \
    ...
    apt-get -yq install {your-pkgs} && \
    ...
备选方案3:环境DEBIAN_前端=非交互式

设置
ENV DEBIAN_FRONTEND noninteractive
也是一种选择,但这是非常不鼓励的

另一种方法是在Dockerfile的开头设置,然后在结尾取消设置

解决方案特征:

  • ENV
    指令将在生成后保持环境变量(不推荐),此外
  • 如果忘记将其设置回默认值,则很容易出错
  • 因为它是用
    ENV
    设置的,所以它将被所有映像继承,并包含从映像构建的内容,从而有效地改变它们的行为。(如[]中所述)使用这些图像的用户在以交互方式安装软件时会遇到问题,因为安装程序不会显示任何对话框
  • 默认前端是DEBIAN_frontend=newt(请参见[]),因此必须在文件末尾设置它
例如:

ARG DEBIAN_FRONTEND=noninteractive
...
RUN apt-get -yq install {your-pkgs}
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install {your-pkgs}
# Set for all apt-get install, must be at the very beginning of the Dockerfile.
ENV DEBIAN_FRONTEND noninteractive
...
# Non-interactive modes get set back.
ENV DEBIAN_FRONTEND newt
# Set the frontend and then install your package
RUN export DEBIAN_FRONTEND=noninteractive && \
    ...
    apt-get -yq install {your-pkgs} && \
    ...
备选方案4:运行导出DEBIAN_前端=非交互式

解决方案特征:

  • 与备选方案2非常相似
  • 通过解耦,内聚受到了影响:为什么会导出这个变量以及它所属的对象(apt-get)
  • 作用域是
    运行
    ,不会影响其他指令
例如:

ARG DEBIAN_FRONTEND=noninteractive
...
RUN apt-get -yq install {your-pkgs}
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install {your-pkgs}
# Set for all apt-get install, must be at the very beginning of the Dockerfile.
ENV DEBIAN_FRONTEND noninteractive
...
# Non-interactive modes get set back.
ENV DEBIAN_FRONTEND newt
# Set the frontend and then install your package
RUN export DEBIAN_FRONTEND=noninteractive && \
    ...
    apt-get -yq install {your-pkgs} && \
    ...
更多阅读内容(参考资料)


这是一个持续存在的问题,没有很好的解决方案……我同意这一点,它是次优的,但它可以工作:

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y apt-utils 2>&1 | \
    grep -v "^debconf: delaying package configuration, since apt-utils.*"
说明:

  • grep-v
    反向匹配,以该开头的行将开始
  • 如果在运行时不需要ARG,则ARG是新的ENV
  • 然后,当从头开始构建图像时,我们可以使用apt get全天不显示错误
证明这是有效的:

您能为“忽略它是安全的”评论提供参考吗?这是一个已知的警告,请参见以下示例:(这种情况发生在具有交互式配置的软件包中,它会向您提问-这意味着将跳过交互式配置,但您甚至不需要交互式配置,并且仍然需要默认设置,因为您正在运行自动安装)。这并不总是一个不可忽略的警告,它取决于您正在安装的特定软件包。有时,配置是必要的,您必须执行交互式安装,或者找到其他方式为其提供所需的配置。我使用了“备选方案2:动态”:非常干净方便,我不再有令人困惑的警告。我选择了备选方案1,但仍然收到警告。我的Dockerfile以节点10.16.2 WORKDIR/usr/src/app ARG DEBIAN_FRONTEND=noninteractive开始,我运行了
docker build--无缓存-t node-10-16-2-plus-chrome。
注意,备选方案1不起作用!因为Builld参数仅在Dockerfile中用美元符号引用时解释。生成参数与环境变量不同,并且不会传播到运行层(与环境变量不同)。这不是修复或“最佳选项”。您只是在视觉上过滤掉错误,从而使您的Dockerfile变得杂乱无章,只不过是为了美观。@d作为最佳选择,我并不是有意暗示良好。我已将其替换为“次优”