Skip to content

Docker Basics

Docker is a platform for packaging applications and dependencies into containers - isolated, lightweight, and portable environments.

ConceptDescription
ImageBlueprint for creating a container
ContainerRunning instance of an image
DockerfileFile defining how to build an image
VolumePersistent storage for containers
NetworkConnectivity between containers
Terminal window
# Pull image
docker pull node:20-alpine
# Run container
docker run -d -p 3000:3000 --name myapp node:20-alpine
# List containers
docker ps
# Stop & remove
docker stop myapp && docker rm myapp
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
services:
web:
build: .
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: secret
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
  • Use multi-stage builds to reduce image size
  • Always use .dockerignore to exclude unnecessary files
  • Prefer alpine images for production