# Docker & Containerization — Fastify: Building High-Performance Node.js APIs

Source: https://www.skillbyai.com/en/fastify/ff-docker

> Containerize a Fastify app with a minimal Dockerfile and a multi-stage build for smaller images.

## Dockerfile for Fastify

A minimal Dockerfile to run your Fastify app in a container.

```dockerfile
FROM node:22-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --omit=dev

COPY . .

EXPOSE 3000

CMD ["node", "server.js"]
```

## Multi-stage builds

Reduce image size by building in one stage and copying the essentials to a final stage.

```dockerfile
FROM node:22 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .

FROM node:22-alpine
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app . 
EXPOSE 3000
CMD ["node", "server.js"]
```
