Skip to content
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

Inline the RUN operations so that disk space is freed #22

Closed
shift opened this issue Feb 2, 2016 · 4 comments
Closed

Inline the RUN operations so that disk space is freed #22

shift opened this issue Feb 2, 2016 · 4 comments

Comments

@shift
Copy link

shift commented Feb 2, 2016

The following changes for the ruy container provide a 8.00% improvement in size:

FROM iron/base

RUN apk update && apk upgrade

RUN apk add libxml2 libxslt libevent libffi glib ncurses readline openssl yaml zlib curl
RUN apk add mariadb-libs libpq
RUN apk add ruby ruby-io-console

# Clean APK cache
RUN rm -rf /var/cache/apk/*

Becomes:

FROM alpine

RUN apk update && apk upgrade \
    && apk add ca-certificates libxml2 libxslt libevent libffi glib ncurses readline \
    openssl yaml zlib curl  mariadb-libs libpq ruby ruby-io-console \
    && rm -rf /var/cache/apk/*

The output of the original image virtual size is 40.07 MB while the inlined version is 37.02 MB, in-keeping with the README's provide the smallest possible images, this is an improvement :)

This is because the layers are overlaid on each previous layer, you're currently leaving the packages in the apt RUN line layers and then saying they don't exist in the last layer, so the data is still pulled down.

In-lining the commands leaves you with only one additional layer on the base image with all of the cleanup occurring in it :).

@jocubeit
Copy link

jocubeit commented Feb 2, 2016

Impressive @shift, not something I had thought about.

@treeder
Copy link
Contributor

treeder commented Feb 2, 2016

Nice, tested this out on the node image and it dropped it a good 5-6 MB. https://github.com/iron-io/dockers/blob/master/node/Dockerfile

@shift
Copy link
Author

shift commented Feb 2, 2016

Happy to help :)

treeder added a commit that referenced this issue Feb 2, 2016
@neg3ntropy
Copy link

Was about to post this as well while looking at the java image. BTW this is a general rule: you just never do cleanup of temporary files in a RUN by itself, always chain it to the RUN that brought in the files in the first place. Cheers

@treeder treeder closed this as completed Feb 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants