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

How to install rpm to /usr/bin instead of /opt/app-root/bin

发布于 2020-11-26 15:23:43

I'm trying to create rpm package for Centos7. So I create Dockerfile from Centos7 image and build rpm inside. It build successfully, but there is one problem: when I try to use this rpm as package in other Dockerfiles it installs into /opt/app-root/bin when I need to install it to usr/bin.

Here is my Dockerfile for building rpm (I also install it inside just to check it works):

FROM centos/python-27-centos7:latest

USER root

RUN yum update -y
RUN yum install rpm-build -y

WORKDIR /usr/src/app
COPY . .

RUN bash -c "pip install --upgrade pip"

RUN git clone https://github.com/klbostee/typedbytes.git
RUN bash -c "cd typedbytes && python setup.py install"

RUN bash -c "pip install -r requirements.txt"

RUN git clone https://github.com/klbostee/dumbo

RUN bash -c "cd dumbo && python setup.py \
    --command-packages=pypi2rpm.command bdist_rpm2 \
    --binary-only \
    --tmppath /tmp/ \
    --dist-dir=. \
    --no-autoreq \
    --name=python27-dumbo \
    --python=python"

RUN cd dumbo && yum install *.rpm -y
CMD ["bash"]

I use docker run -ti -v ... after that and copy rpm from mounted volume. After that I try to use this rpm in another Dockerfile, it installs it successfully, but can't find command to use it : no such file or directory I suppose it installs rpm to the wrong path and then cannot find it.

I suppose my problem is using USER root - look like that is why it try to install it to /opt/root/ but I don't know how to change it.

How to install it to usr/bin? Do I need to create another user inside Docker? Or what?

Questioner
Mikhail_Sam
Viewed
0
Mikhail_Sam 2020-12-02 19:40:22

I start to think that my problem is a wrong image chosen to built app. I tried to use another one:

FROM centos:centos7

And install python to it manually. And this solves the problem - in this image I have root privileges when writing Dockerfile and my library installs to /usr/bin as I wish. So the solution is:

FROM centos:centos7
MAINTAINER The CentOS Project <cloud-ops@centos.org>

RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN yum -y install python-pip; yum clean all
RUN yum -y install rpm-build
RUN yum -y install git, which


RUN pip install --upgrade pip
RUN pip install --upgrade setuptools

RUN mkdir app
COPY . /app
WORKDIR /app 

RUN git clone https://github.com/klbostee/typedbytes.git
RUN cd typedbytes && python setup.py install
...

and so on.