Docker-alpine: Unable to bring down container size after deleting a package

Created on 18 Jun 2015  路  1Comment  路  Source: gliderlabs/docker-alpine

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"

question

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:

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/*

>All comments

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/*
Was this page helpful?
0 / 5 - 0 ratings

Related issues

oarmstrong picture oarmstrong  路  4Comments

kalaksi picture kalaksi  路  3Comments

gliptak picture gliptak  路  4Comments

nrvnrvn picture nrvnrvn  路  4Comments

u6f6o picture u6f6o  路  4Comments