Removing what was added in the previous layer in docker

I am trying to reduce the image size of dockers. In my docker file, I do this:

FROM crystal/centos
MAINTAINER crystal

ADD ./rpms/test.rpm ./rpms/ 
RUN yum -y --nogpgcheck localinstall /rpms/test.rpm 

from what I understand, the ADD command is in its own layer, and then the RUN is in another layer. Therefore, after installing rpm, how can I delete the source directory /rpms.

+4
source share
4 answers

use this technique

RUN curl http://someaddress/test.rpm &&\
    yum -y --nogpgcheck localinstall /rpms/test.rpm &&\
    rm test.rpm
+4
source

You cannot delete data from previous layers. If the folder /rpms/is huge and you absolutely don't need its data in your docker image, you have at least two solutions:

  • ADD ( ), single RUN :
    • rpm
    • rpm
    • rpm
+3

RUN rm -rf /rpms

. , df . , , . , , yum . , yum.

+1

, . , (RO) ?

AUFS, ( , 1.2 ):

  • /var/lib/docker/aufs/diff
  • , /var/lib/docker/aufs/layers/${CONTAINER_ID}.

, , /var/lib/docker/aufs/layers/${CONTAINER_ID}, /var/lib/docker/aufs/diff/.

. . .

+1
source

All Articles