Docker image size and layer caching best practices

Viewed 57

Might be a noob question here. I'm playing around with Docker builds for my Meteor project and noticed that in this repo for a popular base image, the author suggests using the devbuild during development and the onbuild for production.

devbuild

ONBUILD RUN bash $METEORD_DIR/lib/install_meteor.sh  # install dependencies
ONBUILD COPY ./ /app
ONBUILD RUN bash $METEORD_DIR/lib/build_app.sh  # build the app

vs onbuild

ONBUILD COPY ./ /app
ONBUILD RUN bash $METEORD_DIR/lib/install_meteor.sh  # install dependencies
ONBUILD RUN bash $METEORD_DIR/lib/build_app.sh  # build the app

I assume the former uses Docker's layer caching capability to speed up the build, and he warns that using the devbuild for the final build would result in a much larger image than necessary since it contains the full meteor installation.

This seems to contradict what I've read in guides like this from the Docker Quickstart, and this one, that recommend installing dependencies first so they can be cached.

Is there a difference between the situation presented in the meteor guide vs the node guides, and what's the best way to build these dependencies in production?

0 Answers
Related