Docker has revolutionized how we package and deploy applications. As a DevOps engineer, understanding containerization is essential for managing infrastructure at scale.

What is Docker?

Docker is a containerization platform that allows you to package your application and all its dependencies into a lightweight, portable container. Instead of shipping your application with a full operating system, Docker containers share the host OS kernel while maintaining isolation.

Key Benefits

Getting Started with Docker

Your First Dockerfile

A Dockerfile is a blueprint for creating Docker images. Here’s a practical example:

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

Breaking it down:

Build and Run

# Build the image
docker build -t my-app:1.0 .

# Run the container
docker run -p 3000:3000 my-app:1.0

# Run in background (detached mode)
docker run -d -p 3000:3000 my-app:1.0

Docker Compose for Multi-Container Apps

When you need multiple services working together (web app + database + cache), Docker Compose is your friend:

version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - db
    environment:
      DATABASE_URL: postgres://user:password@db:5432/myapp
  
  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: myapp
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data:

Start the entire stack with a single command:

docker-compose up -d

Best Practices

  1. Use specific base image versions - Avoid latest tags which can break unexpectedly
  2. Keep images small - Use Alpine variants of images (they’re 10x smaller)
  3. Multi-stage builds - Build in one stage, copy artifacts to final stage
  4. Don’t run as root - Create a non-root user in your container
  5. Security scanning - Use docker scan to find vulnerabilities

Next Steps

Docker is foundational for modern DevOps. Start with simple applications, build containerized solutions, and scale with confidence.


Want to learn more? Check out the Docker documentation.