How to write faster, leaner Dockerfiles for Node with Yarn and Alpine

Summary of image sizes and build times

Overview

Setting up our application

Our kickstart application

Bootstrapping our bootstrapper

Docker image 1 — Node base image + NPM

  • Cold build: 119 seconds
  • Warm build: 89 seconds
Microbadger for Node + NPM image
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
thenayr/node-npm 6.9.5 3954ac331877 2 hours ago 742 MB

Docker image 2 — Alpine Node base image + NPM

Dockerfile for Alpine Node
  • Cold build: 99 seconds
  • Warm build: 91 seconds
Microbadger image layer size breakdown
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
thenayr/node-npm 6.9.5-alpine 4298630b62dc About an hour ago 132 MB
thenayr/node-npm 6.9.5 3954ac331877 2 hours ago 742 MB

Docker image 3 — Node base image + Yarn

Dockerfile for Yarn install
Script to delete devDependencies in our yarn setup
  • Cold build: 110 seconds
  • Warm build: 78 seconds
Microbadger for Node + Yarn
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
thenayr/node-npm 6.9.5-yarn e0c6ba52878a 8 minutes ago 706 MB
thenayr/node-npm 6.9.5-alpine 4298630b62dc 18 hours ago 132 MB
thenayr/node-npm 6.9.5 3954ac331877 19 hours ago 742 MB

Docker image 4 — Alpine Node base image + Yarn

Dockerfile for Alpine Node with Yarn
  • Cold build: 86 seconds
  • Warm build: 79 seconds
Repository           Size
6.9.5-alpine-yarn : 97.7 MB
6.9.5-yarn : 706 MB
6.9.5-alpine : 132 MB
6.9.5 : 742 MB

Summary

DO IT.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan van Niekerk

Ryan van Niekerk

DevOps Engineer at Lonely Planet, Ketogenic freak. All views and opinions are strictly my own.