Docker在安装apt-utils时遇到问题

pea*_*een 43 apt docker

我正在尝试apt-utils在Docker 上安装,因为当我刚刚做的时候apt-get update,我收到了错误:debconf: delaying package configuration, since apt-utils is not installed.所以我添加了一行安装apt-utils(连同curl):

RUN apt-get update && apt-get install -y apt-utils && apt-get install -y curl
Run Code Online (Sandbox Code Playgroud)

但是,我仍然遇到这个错误,导致我相信我的命令不起作用.当我尝试构建图像时,下面是我的输出.

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
Run Code Online (Sandbox Code Playgroud)

造成这种情况的原因是什么?如何解决?谢谢!

Leo*_*o K 58

这实际上不是一个错误,忽略它是安全的.我已经构建了大量的容器映像而没有任何apt-utils,无论这个警告消息如何,所有的软件包安装都会正常运行.

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

注意如果您安装apt-utils,您将收到其他警告(因为现在安装程序可以运行交互式配置并将尝试并失败).要取消这些并使包含具有默认值的交互式配置的包,请像这样运行apt-getDEBIAN_FRONTEND=noninteractive apt-get install -y pkgs....

  • 这是一个已知的警告,请参见此处:https://github.com/phusion/baseimage-docker/issues/319#issuecomment-262662165(这种情况发生在具有交互式配置的软件包中,它会向您询问问题 - 这意味着跳过了交互式配置,但您甚至不需要它并且仍然需要默认值,因为您正在运行自动安装). (11认同)
  • 您可以为“可以放心忽略它”注释提供参考吗? (4认同)
  • 它并不总是一个可忽略的警告,它取决于您正在安装的特定软件包。有时配置是必要的,您必须执行交互式安装或找到其他方式来为其提供所需的配置。 (3认同)

Key*_*r00 15

搜索在互联网上后,我已经找到了一些替代品值得一提的,而不是每次投入时间DEBIAN_FRONTEND=noninteractive在前面apt-get install -y {your-pkgs}

选择1:ARG DEBIAN_FRONTEND =非交互式

ARG指令定义了一个变量,用户可以在构建时使用--build-arg =标志使用docker build命令将其传递给构建器。(参考:[ 6 ])

解决方案特点:

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

例:

ARG DEBIAN_FRONTEND=noninteractive
...
RUN apt-get -yq install {your-pkgs}
Run Code Online (Sandbox Code Playgroud)

选择2:即时

这是Leo K的解决方案。

解决方案特点:

  • 可以在需要的地方设置。所以是一个很好的细粒度解决方案。
  • 可以在特定命令中将其设置为其他值,因此不能全局设置。
  • 范围是RUN,不会影响其他指令。

例:

RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install {your-pkgs}
Run Code Online (Sandbox Code Playgroud)

选择3:ENV DEBIAN_FRONTEND =非交互式

设置ENV DEBIAN_FRONTEND noninteractive也是一种替代方法,但是强烈建议不要这样做。

另一种方法是在乞讨处设置,在Dockerfile的末尾取消设置。

解决方案特点:

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

例:

# 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
Run Code Online (Sandbox Code Playgroud)

备选方案4:RUN导出DEBIAN_FRONTEND =非交互式

解决方案特点:

  • 替代方案2非常相似
  • 通过脱钩,凝聚力受到了损害:为什么要输出该变量及其所属的变量(apt-get)。
  • 范围是RUN,不会影响其他指令。

例:

# Set the frontend and then install your package
RUN export DEBIAN_FRONTEND=noninteractive && \
    ...
    apt-get -yq install {your-pkgs} && \
    ...
Run Code Online (Sandbox Code Playgroud)

阅读更多(参考)

  • 我使用了“替代方案 2:即时”:非常干净和方便,我不再有令人困惑的警告 (2认同)
  • 我选择替代方案 1,但仍然收到警告。我的 Dockerfile 以“FROM node:10.16.2 WORKDIR /usr/src/app ARG DEBIAN_FRONTEND=noninteractive”开头,然后运行“docker build --no-cache -t node-10-16-2-plus-chrome”。 (2认同)

小智 6

请运行apt-get install apt-utils并查看\xc3\xa0。安装了,没有任何警告。

\n