无法在Dockerfile中安装软件包[E:子过程/usr/bin/dpkg返回错误代码(1)]

发布于 2025-02-09 02:17:06 字数 933 浏览 1 评论 0原文

我正在尝试在Ubuntu 16.04容器中安装一个私人软件包。为此,我使用dockerfile中的以下行来构建使用基本图像ubuntu 16.04的图像,其中nf是一个参数设置为各种软件包名称(不包括存储库地址):

FROM ubuntu:16.04
ENTRYPOINT ["/sbin/init"]
SHELL ["/bin/bash", "-c"]
ARG nf
RUN touch /etc/apt/sources.list.d/cinar.list
RUN echo -e $"<repository addresses are here>" >> /etc/apt/sources.list.d/cinar.list
RUN apt-get update
RUN apt-get install -y $nf

最后一行结果带有以下错误:

E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/bash -c apt-get install -y $nf' returned a non-zero code: 100

但是,当我从dockerfile删除此行并构建图像时,然后进入容器内并使用命令apt -get install -y packagename,此错误不会发生。由于我正在执行自动化任务,并且无法在容器上手动安装软件包,因此我将不胜感激。我已经尝试了列出的解决方案在这里/a>,它们似乎都没有用。

I am trying to install a private package inside an Ubuntu 16.04 container. To do this, I am using the following line in a Dockerfile to build an image with base image Ubuntu 16.04 where nf is an argument set to various package names (repository addresses are not included):

FROM ubuntu:16.04
ENTRYPOINT ["/sbin/init"]
SHELL ["/bin/bash", "-c"]
ARG nf
RUN touch /etc/apt/sources.list.d/cinar.list
RUN echo -e 
quot;<repository addresses are here>" >> /etc/apt/sources.list.d/cinar.list
RUN apt-get update
RUN apt-get install -y $nf

The last line results with the following error:

E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/bash -c apt-get install -y $nf' returned a non-zero code: 100

However, when I remove this line from the Dockerfile and build the image, then go inside the container and use the command apt-get install -y packagename, this error does not occur. I would appreciate any help on this issue since I am doing an automation task and cannot manually install packages on containers. I have tried the solutions listed here, and none of them seems to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

徒留西风 2025-02-16 02:17:06

bash中,$“ repository-addresses”repository-addresses完全相同。

repository-addresses对于/etc/apt/sources.list.d/gh.list中的条目无效,也不是有效的变量名称。

如果您将repository-addresses作为build-arg,则应将其重命名为repository_addresses,并将其与以下方式一起使用:

ARG repository_addresses
...
RUN echo -e "$repository_addresses" >> /etc/apt/sources.list.d/cinar.list

In bash, $"repository-addresses" is exactly the same as repository-addresses.

repository-addresses is not valid for entries in /etc/apt/sources.list.d/*.list, nor is it a valid variable name.

If you have repository-addresses as build-arg, you should rename it to repository_addresses and use it with :

ARG repository_addresses
...
RUN echo -e "$repository_addresses" >> /etc/apt/sources.list.d/cinar.list
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文