# Docker for Full-Stack Apps

> Package your API and run PostgreSQL and Redis locally with Docker and Docker Compose, so every machine runs the same stack. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/full-stack/docker
Last updated: 2026-11-28

Package your API and run PostgreSQL and Redis locally with Docker and Docker Compose, so every machine runs the same stack.

Intermediate · about 6 hours · difficulty 3/5

Learn first: [Environments, Config and Secrets](https://www.internhack.in/roadmaps/tracks/full-stack/environment-and-config), [Terminal and Command Line](https://www.internhack.in/roadmaps/tracks/full-stack/terminal-basics)

Docker packages your app with its runtime and dependencies into an **image** that runs the same everywhere. Even if you deploy to a platform that builds for you, Docker is the easiest way to run PostgreSQL and Redis locally.

### Core concepts

- **Image**: a read-only template built from a Dockerfile.
- **Container**: a running instance of an image.
- **Volume**: persistent storage, so your local database survives restarts.
- **Port mapping**: expose a container port (5432) on your machine.

### A good Node.js Dockerfile

- Start from an official slim Node LTS image.
- Copy package files first and install dependencies, so the layer is cached.
- Use a **multi-stage build**: build in one stage, copy only the output and production dependencies into a small final image.
- Run as a non-root user and add a .dockerignore (node_modules, .env, .git).

### Docker Compose

One docker-compose.yml can start your API, PostgreSQL and Redis together with a single command, with environment variables and health checks. New teammates go from clone to running app in minutes.

### Pitfalls

- Copying .env files or secrets into images.
- Huge images built from full base images with dev dependencies.
- Losing local data because no volume was configured.

You are ready to move on when docker compose up starts your API, PostgreSQL and Redis, and your API image is a multi-stage build under a few hundred megabytes.

## Key concepts

- **Images, containers and volumes**
- **Writing a Dockerfile**
- **Layer caching**
- **Multi-stage builds**
- **Docker Compose**
- **.dockerignore and non-root users**
- **Health checks**

## Mini project

Write a multi-stage Dockerfile for your API and a docker-compose.yml that runs the API, PostgreSQL and Redis with volumes and health checks, then document one-command setup in the README.

## Check yourself

Why copy package.json and install dependencies before copying the rest of your source code in a Dockerfile?

## Free resources

- [Docker: Get started](https://docs.docker.com/get-started/) (Docker)
- [Docker Compose](https://docs.docker.com/compose/) (Docker)
- [Docker Roadmap](https://roadmap.sh/docker) (roadmap.sh)

Previous: [Environments, Config and Secrets](https://www.internhack.in/roadmaps/tracks/full-stack/environment-and-config) · Next: [Deploying on Vercel](https://www.internhack.in/roadmaps/tracks/full-stack/vercel)

## More in Configuration, Containers and Deployment

- [Environments, Config and Secrets](https://www.internhack.in/roadmaps/tracks/full-stack/environment-and-config)
- [Docker for Full-Stack Apps](https://www.internhack.in/roadmaps/tracks/full-stack/docker)
- [Deploying on Vercel](https://www.internhack.in/roadmaps/tracks/full-stack/vercel)
- [Deploying on Render or Railway](https://www.internhack.in/roadmaps/tracks/full-stack/render)
- [Managed Databases, Domains and HTTPS](https://www.internhack.in/roadmaps/tracks/full-stack/managed-postgres-and-domains)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Full-Stack Developer Roadmap](https://www.internhack.in/roadmaps/tracks/full-stack)
