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

camsedfj  于 2023-01-16  发布在  Docker
关注(0)|答案(4)|浏览(309)

我正在尝试在Docker上安装apt-utils,因为当我刚刚执行apt-get update时,我收到错误:所以我添加了一行来安装apt-utils(沿着curl):

RUN apt-get update && apt-get install -y apt-utils && apt-get install -y 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

是什么原因导致了这种情况?我该如何解决?

hc8w905p

hc8w905p1#

这实际上不是一个错误,忽略它是安全的。我已经构建了大量的容器映像,其中任何一个都没有apt-utils,不管这个警告消息,所有的包安装都可以正常进行。
无论如何,如果你想安装apt-utils,它会给予你这个警告 * 一次 *,然后它会在以后调用apt-get时消失(正如你在自己的日志中看到的,curl安装时没有这个消息)。
注意如果你安装了apt-utils,你会收到其他警告(因为现在安装程序 * 可以 * 运行交互式配置,并且会尝试运行交互式配置,但是会失败)。要取消这些警告,并使软件包具有默认的交互式配置,请像DEBIAN_FRONTEND=noninteractive apt-get install -y pkgs....这样运行apt-get

bq9c1y66

bq9c1y662#

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

    • 备选案文1:ARG DEBIAN_前端=非交互式**
    • 重要信息**:根据反馈,选项2和选项3对你们大多数人都有效,而选项1不起作用。这就是为什么这个选项被交叉,但为了可追溯性和完整性的原因而保留。

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

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

示例:

ARG DEBIAN_FRONTEND=noninteractive
...
RUN apt-get -yq install {your-pkgs}
    • 备选案文2:动态**
  • 这是里奥·K的解决方案 *

溶液特性:

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

示例:

RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install {your-pkgs}
    • 备选案文3:环境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
    • 备选案文4:运行导出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} && \
    ...
k10s72fa

k10s72fa3#

请运行apt-get install apt-utils,瞧,安装完毕,没有警告。

bfhwhh0e

bfhwhh0e4#

这是一个持续存在的问题,没有很好的解决方案......我选择了这个,它不是最佳的,但它起作用了:

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,那么它就是新的ENV。
  • 然后,我们可以整天使用apt-get,从头构建映像时不会显示该错误。

证明这是可行的:https://asciinema.org/a/WJCDEYcxCIy6EF7eXw0MAnK3c

相关问题