Docker image build Error : unable to find user admin: no matching entries in passwd file

Docker image build Error : unable to find user admin: no matching entries in passwd file

这是我的 Dockerfile 的样子:


[root@centos7 ~]# cat Dockerfile
# syntax=docker/dockerfile:1
#use centos image
FROM centos

# Add none root user
CMD  useradd admin && echo "admin:admin" 
CMD  chpasswd
CMD  adduser admin sudo
USER admin

#install python git and gcc libs

RUN sudo yum install python3 python3-devel git gcc sassc redhat-rpm-config libxslt-devel  \
    bzip2-devel openldap-devel libjpeg-devel freetype-devel

当我午餐构建图像时,我遇到了以下错误:


Step 6/24 : RUN sudo yum install python3 python3-devel git gcc sassc redhat-rpm-config libxslt-devel      bzip2-devel openldap-devel libjpeg-devel freetype-devel
 ---> Running in 4d6c76160178
unable to find user admin: no matching entries in passwd file


任何人都知道 idea/suggestion 为什么找不到密码文件中的用户条目?

如下所示将 CMD 替换为 运行 将解决您的问题。

  #Add none root user
  RUN  useradd -m admin && echo "admin:admin" |  chpasswd &&  usermod -aG wheel  admin

您的下一步是在容器中添加 sudo 命令,因为它默认不存在。