Dockerfile 无法运行 apt-get(退出代码:100)

问题描述 投票:0回答:1

我正在与 yocto 合作,我正在尝试使用此基础构建我的自定义图像:yocto-ubuntu-20.04

我有这个简单的 docker 文件:

FROM reliableembeddedsystems/yocto:ubuntu-20.04-base
RUN apt-get update

但是我在构建时遇到权限错误:

user@user$ sudo docker build .
[...]
------                                                                                                               
 > [2/2] RUN apt-get update:
0.214 Reading package lists...
0.753 E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
0.753 E: Unable to lock directory /var/lib/apt/lists/
------
Dockerfile:2
--------------------
   1 |     FROM reliableembeddedsystems/yocto:ubuntu-20.04-base
   2 | >>> RUN apt-get update
   3 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update" did not complete successfully: exit code: 100

如果我将

sudo
添加到
RUN apt-get update
行,我会收到一个不同的错误,要求输入密码:

 > [2/2] RUN sudo apt-get update:                                                                                    
0.207 sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
------
Dockerfile:2
--------------------
   1 |     FROM reliableembeddedsystems/yocto:ubuntu-20.04-base
   2 | >>> RUN sudo apt-get update
   3 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c sudo apt-get update" did not complete successfully: exit code: 1

正确的使用方法是什么?

另一个问题:如果使用基础镜像运行容器,我注意到我可以使用 sudo。但是,我怎么知道密码呢?这里可以使用

sudo
吗?

docker ubuntu dockerfile yocto apt-get
1个回答
0
投票

基础镜像似乎设置了 root 以外的用户。可以使用以下方法修复此问题:

FROM reliableembeddedsystems/yocto:ubuntu-20.04-base
USER root
RUN apt-get update
© www.soinside.com 2019 - 2024. All rights reserved.