New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to bring down container size after deleting a package #45

Closed
sivaramsk opened this Issue Jun 18, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@sivaramsk
Copy link

sivaramsk commented Jun 18, 2015

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"

@andyshinn andyshinn added the question label Jun 27, 2015

@andyshinn

This comment has been minimized.

Copy link
Collaborator

andyshinn commented Jun 27, 2015

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/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment