为什么这个 apt-get 命令在一种情况下有效,而在另一种情况下无效?

Mig*_*ell 1 command-line apt docker

我正在尝试使用以下命令将 plpython 包添加到我的 docker 容器(运行 Ubunutu 映像)(RUN 是 docker 命令,如果您不了解 Docker,则可以忽略该命令):

RUN apt-get install -y postgresql-plpython-$PG_MAJOR=$PG_VERSION

但是,这会导致以下错误:

E: Unable to locate package postgresql-plpython-9.4
E: Couldn't find any package by regex 'postgresql-plpython-9.4'
INFO[0005] The command [/bin/sh -c apt-get install -y postgresql-plpython-$PG_MA
JOR=$PG_VERSION] returned a non-zero code: 100
Run Code Online (Sandbox Code Playgroud)

但是,如果我将这个相同的命令插入到现有 Dockerfile 的这一部分中(即我添加了 line postgresql-plpython-$PG_MAJOR=$PG_VERSION \,该命令将起作用。

我对 apt-get 不太了解,所以有人可以解释为什么在父 Dockerfile 的上下文中找到该包,而不是我的 Dockerfile 吗?我该怎么做才能找到包裹?

And*_*hen 5

基础镜像的Dockerfile有如下指令:

rm -rf /var/lib/apt/lists/*
Run Code Online (Sandbox Code Playgroud)

这将清除由 下载的包列表apt-get update。这就是您收到错误的原因。要解决此问题,请apt-get update在您的 Dockerfile 中再次执行。