Friday, April 8, 2022

[SOLVED] Dockerfile Permission Denied when using yum install

Issue

I'm trying to create Dockerfile from this Image: https://hub.docker.com/r/centos/python-27-centos7

My 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"]

But I got next error:

 => 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.
------

I tried add sudo but still doesn't work. What is wrong here?


Solution

Try to use the user 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"]


Answered By - Abdullah Al-Hallak
Answer Checked By - Gilberto Lyons (WPSolving Admin)