Docker packages an application together with everything it needs to run, so it behaves the same on your laptop as it does in production.

Why Docker?

"Works on my machine" problems usually come from mismatched dependencies or OS differences. Containers eliminate that gap by shipping the whole environment.

Images vs Containers

An image is a read-only template (your app + dependencies + OS libraries). A container is a running instance of that image.

Writing a Dockerfile

dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "server.js"]

Common Commands

bash
docker build -t my-app .
docker run -p 3000:3000 my-app
docker ps
docker stop <container_id>

Containers share the host's kernel, which makes them far lighter than full virtual machines.

DockerDevOpsContainers