简体   繁体   中英

Reclaim free space in docker images

I have a dockerfile which basically does:

FROM debian
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y build-essentials automake autoconf libtool
WORKDIR /opt/build
RUN git clone https://somestuff . && make install clean
RUN rm -rf /opt/build && apt-get remove -y build-essentials automake autoconf libtool

When done, I have a 900MB image, whit only (as shown by df in the container) 40GB used

How can I improve my build strategy in order to keep the image a reasonable size?

Regards

Xavier

Split dockerfile to multi-stage builds image.

REF https://docs.docker.com/build/building/multi-stage/

Dockerfile:

#####
# base (init base image)
#####
FROM debian AS base
ENV DEBIAN_FRONTEND=noninteractive


#####
# build-somestuff (temp build image)
#####
FROM base AS build-somestuff
WORKDIR /opt/build
RUN apt-get update && apt-get install -y build-essentials automake autoconf libtool
RUN git clone https://somestuff . && make install clean
# RUN rm -rf /opt/build && apt-get remove -y build-essentials automake autoconf libtool


#####
# main (final image)
#####
FROM base AS main

COPY --from=build-somestuff /opt/build/somestuff   /bin/somestuff
WORKDIR /documents
VOLUME /documents
CMD ["/bin/bash"]

final image is main, not temp build image (build-somestuff) main use COPY copy build make file from build-somestuff

Please reference https://hub.docker.com/r/asciidoctor/docker-asciidoctor/dockerfile for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM