我正在尝试构建 Dockerfile。但执行后出现此错误:
Sending build context to Docker daemon 31.08MB
Step 1/5 : FROM davidrazd/discord-node-10
---> 0ad384ff6003
Step 2/5 : RUN apt-get update
---> Running in 9fb4313d8011
Reading package lists...
W: chmod 0700 of directory /var/lib/apt/lists/partial failed - SetupAPTPartialDirectory (1: Operation not permitted)
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
The command '/bin/sh -c apt-get update' returned a non-zero code: 100
我还尝试放入sudo
dockerfile 以确保我拥有 root 身份的完全访问权限。
Dockerfile:
# Start writing your Dockerfile easily
FROM davidrazd/discord-node-10
RUN sudo apt-get update
RUN sudo apt-get install -y python-pip
RUN sudo install --upgrade pip
答案1
您导入的图像包含用户规范:
USER container
apt-get update
和命令apt-get install
需要 root 访问权限。在 docker build 中,您可以通过以 root 身份运行容器命令(而不是执行 sudo)来获得 root 访问权限。因此,您的 dockerfile 如下所示:
# Start writing your Dockerfile easily
FROM davidrazd/discord-node-10
USER root
RUN apt-get update \
&& apt-get install -y python-pip \
&& install --upgrade pip
USER container
我建议在进一步编写 Dockerfile 之前先阅读以下内容,因为您还需要使用 apt-get 命令解决其他问题(链接命令、从配置中删除输入、不安装推荐的软件包以及在安装命令后进行清理):https://docs.docker.com/develop/develop-images/dockerfile_best-practices/