The first decision to make is to pick a base image. Normally, we would choose a Linux distribution as our base image. For instance, we can pick Ubuntu as our base image:
FROM ubuntu:bionic
We use the bionic tag to specify the exact version of Ubuntu we want (18.04 Long Term Support (LTS)).
However, as it turns out, Node has its own official Docker image available on Docker Hub (hub.docker.com/_/node/). Therefore, we can use the Node Docker image as our base image instead.
To use the Node Docker image as the base image, replace our FROM instruction with FROM node:8:
FROM node:8
For local development, we have been using NVM to manage our Node versions. This is useful when working on multiple JavaScript projects because it allows us to switch between different versions of Node easily. However, there are no such requirements for our container – our backend API image will only ever run one version of Node. Therefore, our Docker image should have a specific version. We used the tag 8 because Node 8 is the latest LTS version available at the time of writing.
The Node Docker image has yarn pre-installed, so there are no more dependencies we need to install.