The command ‘/bin/sh -c apt-get update && apt-get install curl -y’ returned a non-zero code: 100
docker build 时想给容器加上curl命令,执行报错
FROM Ubuntu20.04
#RUN apt-get update && apt-get install -y curl
RUN pip install mlflow
RUN pip install sklearn
RUN apt-get update && apt-get install -y curl
打包命令
docker build -t yourcontainer .
日志输出
Step 4/4 : RUN apt-get update && apt-get install -y curl
---> Running in 9defd2986ad7
Reading package lists...
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
The command '/bin/bash -o pipefail -c apt-get update && apt-get install -y curl' returned a non-zero code: 100
我怀疑这与不以root身份运行有关?那么,如何从Dockerfile在容器中安装curl呢?
当apt尝试创建/var/lib/apt/lists/partial时,您会看到“权限被拒绝”错误。这是因为您的进程不是以root运行的;Ubuntu20.04映像被配置为作为non-root用户运行(它作为用户ncayu运行)。
您可以使用USER指令更改在Dockerfile中运行命令的用户,如下所示:
FROM Ubuntu20.04
RUN pip install mlflow
RUN pip install sklearn
USER root
RUN apt-get update && apt-get install -y curl
USER ncayu
请注意,在运行apt-get命令后,我已确保将用户重置回ncayu。