Docker lets you package an application and all its dependencies into a standardized unit called a container. Containers ensure your app runs the same everywhere — from your laptop to production.
Key Concepts
- Image: A read-only template for creating containers
- Container: A running instance of an image
- Dockerfile: Instructions to build an image
- Registry: A place to store and share images (e.g., Docker Hub)
A Simple Dockerfile for Node.js
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]Essential Commands
docker build -t myapp . # build image
docker run -p 3000:3000 myapp # run container
docker ps # list containers
docker stop <id> # stop container
docker-compose up # start multi-container app