Docker Fundamentals
Docker is a platform for building, shipping, and running applications in containers.
What is a Container?
A container is a lightweight, standalone, executable package that includes everything needed to run an application: code, runtime, system tools, libraries, and settings.
Key Concepts
- Image — a read-only template used to create containers
- Container — a running instance of an image
- Dockerfile — a text file with instructions to build an image
- Volume — persistent storage mounted into a container
- Network — how containers communicate with each other
Basic Commands
bash
# Pull an image
docker pull node:22-alpine
# Run a container
docker run -p 3000:3000 node:22-alpine
# List running containers
docker ps
# Build an image from a Dockerfile
docker build -t my-app .
# Stop a container
docker stop <container-id>Example Dockerfile
dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]