A container is a lightweight, isolated process that bundles an application with everything it needs to run: runtime, libraries, and configuration. Unlike virtual machines, containers share the host OS kernel, making them fast to start and resource-efficient.
Core Concepts
- Image — a read-only blueprint for a container, built from a Dockerfile
- Container — a running instance of an image
- Dockerfile — instructions for building an image layer by layer
- Registry — a storage service for images (Docker Hub, GHCR, ECR)
- Volume — persistent storage mounted into a container
A Minimal Dockerfile
Dockerfiledockerfile
# Start from an official Node base image
FROM node:20-alpine
# Set working directory inside the container
WORKDIR /app
# Copy and install dependencies first (layer caching)
COPY package*.json ./
RUN npm ci --omit=dev
# Copy application source
COPY . .
# Expose the port the app listens on
EXPOSE 3000
CMD ["node", "server.js"]Common Commands
terminalbash
# Build an image tagged 'myapp:latest'
docker build -t myapp:latest .
# Run a container, mapping host port 8080 to container port 3000
docker run -p 8080:3000 myapp:latest
# List running containers
docker ps
# Stop a container
docker stop <container-id>