Few weeks before now, I boostrapped a NodeJS codebase using Docker as part of the requirement was that new team member should be able to get up and running as soon as possible. I came up with a Dockerfile that looked like the below:
# Base Image.
# This image already exists in dockerhub.
# We are just extending its functionalities
FROM node:10
# Already created by the node image
USER node
# Changes directory in the container to this directory
WORKDIR /home/node/app
# Copy package.json and package-lock.json to allow using cached packages
COPY package*.json ./
# Install node dependencies
RUN npm install
# Copy source files to working directory
COPY . .
# Port that the node app will listen to
EXPOSE 5000
Little did I know that some dependencies were missing until I started implementing authentication and password hashing using argon2 package, node-gyp installation started to fail. To get the docker file running, I did some Googling to find this Stackoverflow answer , and my new and working docker file looks like the below:
# Base Image.
# This image already exists in dockerhub.
# We are just extending its functionalities
FROM node:10-alpine
RUN apk add g++ make python
RUN apk add --no-cache --virtual .build-deps make gcc g++ python \
&& npm install --production --silent \
&& apk del .build-deps
# Create and set working directory for image
WORKDIR /app
# Copy package.json and package-lock.json to allow using cached packages
COPY package*.json ./
# Install node dependencies
RUN npm install
# Copy source files to working directory
COPY . .
# Port that the node app will listen to
EXPOSE 5000