使用 yum 安装时 Dockerfile 权限被拒绝

Dockerfile Permission Denied when using yum install

我正在尝试从这个图像创建 Dockerfile:https://hub.docker.com/r/centos/python-27-centos7

我的 Dockerfile:

FROM centos/python-27-centos7:latest

RUN yum install rpm-build -y

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt


CMD ["bash"]

但是我遇到了下一个错误:

 => ERROR [2/9] RUN yum install rpm-build -y                                                                                                                                0.6s
------                                                                                                                                                                           
 > [2/9] RUN yum install rpm-build -y:                                                                                                                                           
#5 0.480 Loaded plugins: fastestmirror, ovl                                                                                                                                      
#5 0.485 ovl: Error while doing RPMdb copy-up:
#5 0.485 [Errno 13] Permission denied: '/var/lib/rpm/Dirnames'
#5 0.579 You need to be root to perform this command.
------

我尝试添加 sudo,但仍然无效。 这里有什么问题?

尝试使用root用户

    FROM centos/python-27-centos7:latest

    USER root
    RUN yum install rpm-build -y
    
    WORKDIR /usr/src/app
    
    COPY requirements.txt ./
    
    RUN pip install --no-cache-dir -r requirements.txt
    
    
    CMD ["bash"]