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

optimize size of images #1

Closed
jderusse opened this issue Nov 19, 2014 · 2 comments
Closed

optimize size of images #1

jderusse opened this issue Nov 19, 2014 · 2 comments

Comments

@jderusse
Copy link

Because docker works with layer and it creates one layer per action on your DockerFile, you should combine actions in the same action to really reduce the size.

When you run

RUN apt-get update && apt-get install -y ruby ruby-dev build-essential sqlite3 libsqlite3-dev
RUN gem install mailcatcher --no-ri --no-rdoc
RUN apt-get remove --purge -y build-essential ruby-dev libsqlite3-dev && apt-get autoclean && apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

The layer #1 will contains the packages build-essential, ruby-dev and libsqlite3-dev then the size of all layers (the size of the image) will not be optilmized.

A better way to reduce size of your images:

RUN \
   apt-get update && apt-get install -y ruby ruby-dev build-essential sqlite3 libsqlite3-dev && \
   gem install mailcatcher --no-ri --no-rdoc && \
   apt-get remove --purge -y build-essential ruby-dev libsqlite3-dev && apt-get autoclean && apt-get clean && \
   rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

In the same action you install and uninstall builds packages. So neither layer will contains those packages.

@jderusse
Copy link
Author

look at my Dockerfile https://github.com/jeremy-derusse/docker-mailcatcher/blob/master/Dockerfile

└─f6fab3b798be Virtual Size: 85.1 MB Tags: debian:latest
  ├─3794a45439d8 Virtual Size: 85.1 MB
  │ └─274f934ebcd9 Virtual Size: 103.7 MB
  │   └─91f173459280 Virtual Size: 259.5 MB
  │     └─f6b600a311b9 Virtual Size: 259.5 MB
  │       └─6b9b0b8a8f62 Virtual Size: 259.5 MB
  │         └─819ea2d64afe Virtual Size: 259.5 MB
  │           └─e4c300a46256 Virtual Size: 259.5 MB Tags: jderusse/mailcatcher:latest
  └─f80eb61398ac Virtual Size: 85.1 MB
    └─5f49055a3c2e Virtual Size: 245.5 MB
      └─8fa522da90bd Virtual Size: 271.6 MB
        └─524317c1f099 Virtual Size: 271.9 MB
          └─6fa2646a041f Virtual Size: 271.9 MB
            └─9167960d09a9 Virtual Size: 271.9 MB
              └─7abb759deb1d Virtual Size: 271.9 MB
                └─f107b79347b9 Virtual Size: 271.9 MB Tags: schickling/mailcatcher:latest

@schickling
Copy link
Owner

Thanks @jeremy-derusse. You're absolutely right. I will create a shell script for mailcatcher as well. This step should have the same effect as your described proposal.

Closing the issue now. Thanks for the heads up!

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

2 participants