I have the below Dockerfile and it creates an image of size 165 MB. When I install the haproxy instead of compiling with "apk add haproxy" the size of the container is 7MB. The size increase mostly corresponds to build-base package. Is there any way that I could bring down the size to the actual root filesystem size itself. The "du -h" command at the / gives 28MB.
FROM gliderlabs/alpine-base:3.2
RUN apk add --update git build-base linux-headers pcre-dev openssl-dev
RUN git clone https://github.com/haproxy/haproxy.git && cd haproxy && \
git checkout v1.5.0 && \
make TARGET=linux2628 CPU=native USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 && \
cp haproxy /usr/local/bin/ && cd .. && rm -rf haproxy
RUN apk del build-base linux-headers pcre-dev openssl-dev
RUN rm -rf /var/cache/apk/*
CMD "/bin/bash"
Your commands to remove packages and clean up cache are in new layers. You cannot remove stuff from previous layers already committed (this is a fundamental Docker thing). Remove the packages and clean up the command in the same layer by adding on to the compound command:
RUN apk add --update git build-base linux-headers pcre-dev openssl-dev && \
git clone https://github.com/haproxy/haproxy.git && cd haproxy && \
git checkout v1.5.0 && \
make TARGET=linux2628 CPU=native USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 && \
cp haproxy /usr/local/bin/ && cd .. && rm -rf haproxy && \
apk del build-base linux-headers pcre-dev openssl-dev && \
rm -rf /var/cache/apk/*
Most helpful comment
Your commands to remove packages and clean up cache are in new layers. You cannot remove stuff from previous layers already committed (this is a fundamental Docker thing). Remove the packages and clean up the command in the same layer by adding on to the compound command: