22 August 2021
Node:Alpine on Docker
Simple guide to smaller Node.js docker images
The standard node.js Docker image is huge and includes a lot of unnecessary dependencies.
To minimize container bloat, there is the Linux Distro Alpine Linux, which is basically made to have a small footprint. This is also partly thanks to musl libc.
Alpine Dockerfile
The node alpine image is available under node:alpine
.
A fairly standard Dockerfile
would look something like this:
FROM node:alpine
WORKDIR /app
COPY package.json /app/package.json
RUN npm install --production
COPY server.js /app/server.js
EXPOSE 8080
CMD npm start
If you run into a problem with missing CA certificates, you can add the following to your Dockerfile
:
RUN apk update && \
apk add ca-certificates && \
update-ca-certificates && \
rm -rf /var/cache/apk/*