0

I'm adding RPMS to my docker image and installing them during the image build. I have the feeling that I have the RPMS twice in my image. At the place where I added them and at the place where RPM installed them. In total there is about 500 MB RPMS (yes they are big) and the final docker image grows from 700 MB base image to 2.1 GB final image.

Question: How can I avoid ADDing them to the image at all.

First idea I had was putting them into a local yum repository and then use yum to install from the repository. This would remove the ADDing to the docker image.

Is there any other possibility? Why can't I mound a external server volume and install the file from there?

Hasan Tuncay
  • 1,090
  • 2
  • 11
  • 30

1 Answers1

2

You have them in /var/cache/dnf.

You may try:

RUN   dnf -y install httpd
RUN   dnf clean all

But you will find that it will not make the image smaller. That is because docker will create the image layer after each RUN section. Therefore you must do:

RUN   dnf -y install httpd && \
      dnf clean all

This will create image layer after both commands and it should be significantly smaller.

msuchy
  • 5,162
  • 1
  • 14
  • 26
  • Understood. But my RPMs are not in any yum repo. Must I create my own local repo server to use yum or is there a more simple way? – Hasan Tuncay Jun 24 '20 at 08:49
  • Then what do you mean by "I added them"? You add them using COPY? – msuchy Jun 24 '20 at 15:55
  • 1
    Then it is the same issue. After ADD docker takes a snapshot of the layer (with rpm in it). Then you install rpm. Docker will take a snapshot of the layer. You must do all in one step (either by `dnf -y install http://myserver/foo.rpm` or you have to squash the layers. See https://stackoverflow.com/a/22714556/3489429 – msuchy Jun 26 '20 at 11:04