Warm tip: This article is reproduced from serverfault.com, please click

Permission denied installing packages when build docker image based on logstash

发布于 2020-11-28 09:55:40

I am working on a project on a logstash docker image and i want to add a layer to a Dockerfile to install python3. The Dockerfile is as follows :

FROM docker.elastic.co/logstash/logstash-oss:7.3.2
RUN yum -y install python3

but when i run docker build . , i get the error

**Step 2/2 : RUN yum -y install python3
 ---> Running in 695de9a8778c
Loaded plugins: fastestmirror, ovl
ovl: Error while doing RPMdb copy-up:
[Errno 13] Permission denied: '/var/lib/rpm/Requirename'
You need to be root to perform this command.
The command '/bin/sh -c yum -y install python3' returned a non-zero code: 1**

what is the solution please ?

Questioner
lynadocker
Viewed
0
Mogi 2020-11-28 23:45:40

The problem is that the logstash container runs as user which is not root and is named logstash, but only root (or a sudoer) can install packages.
The best solution in my opinion is to put USER root in docker file before the installation lines, in order to run the following lines as root.
then install everything.
and finally after installing everything add the line USER logstash to return everything to the way they were before.

example of the Dockerfile:

FROM docker.elastic.co/logstash/logstash-oss:7.3.2
USER root
RUN 'yum update -y && yum -y install python3'
USER logstash