# Docker & Containerization — Fastify

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

> Containerize your Fastify application with Docker.

## Dockerfile for Fastify

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

```dockerfile
FROM node:20-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

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:20 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .

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