简体   繁体   中英

Cannot install package inside Dockerfile [E: Sub-process /usr/bin/dpkg returned an error code (1)]

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 $"<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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM