вторник, 26 января 2021 г.

A Single trick for docker which can greatly reduce docker image size

 Previously I shared some tips for writing better docker files, but recently I discovered one more useful hack. The next tip will reduce image size by excluding any COPY/ADD files, removed files.

FROM centos:8 as build
COPY my_file /tmp
RUN my_build


FROM centos:8

COPY --from=build / /
 

This dockerfile uses multi stage build. In first stage the actual build happens. In second - all the files are just copied to clean base image.

Also, when using thin technique there is no need to group RUNs. Keep in mind that any ENVs, VOLUMEs, CMDs will be saved from last stage only.

Комментариев нет:

Отправить комментарий