← Blog'a Dön
TECHNICAL

What Is Docker? A Beginner's Guide to Containerization

F. Çağrı Bilgehan18 Şubat 20269 dk okuma
DockercontainerizationDevOpsdeploymentsoftware development

What Is Docker? A Beginner's Guide to Containerization

"It works on my machine!" — The phrase developers say most. An application works in the dev environment but crashes on the server. The reason: different environments, different dependencies, different configurations. Docker solves this problem at its root.

What Is Docker?

Docker is a platform that lets you package applications into isolated, portable packages called containers. A container bundles your application with all its dependencies — so it runs the same way everywhere.

Container vs Virtual Machine

| Criteria | Container (Docker) | Virtual Machine (VM) | |----------|-------------------|---------------------| | Size | 10-100 MB | 1-10 GB | | Start time | Seconds | Minutes | | Resource usage | Low | High | | Isolation | Process level | OS level | | Portability | Very high | Medium |

Why Should You Use Docker?

1. Environment Consistency

  • Development = Testing = Production
  • No "works on my machine" problems
  • All dependencies packaged

2. Fast Deployment

  • Deploy with one command
  • Easy rollback
  • CI/CD pipeline compatible

3. Isolation

  • Each application in its own environment
  • No dependency conflicts
  • Security layer

4. Scaling

  • Add new containers when load increases
  • Auto-scaling with Kubernetes
  • Perfect for microservice architecture

Core Docker Concepts

Image

Your application's template — a set of instructions.

Container

A running instance created from an image.

Dockerfile

An instruction file used to create images.

Docker Compose

Configuration for managing multiple containers together.

Docker Hub

Central registry where Docker images are shared.

Dockerfile Example (Next.js)

# Base image
FROM node:20-alpine

# Working directory
WORKDIR /app

# Copy dependencies
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy application files
COPY . .

# Build application
RUN npm run build

# Expose port
EXPOSE 3000

# Start application
CMD ["npm", "start"]

Essential Docker Commands

# Build image
docker build -t my-app .

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

# List running containers
docker ps

# List all containers
docker ps -a

# Stop container
docker stop <container-id>

# List images
docker images

# Remove image
docker rmi <image-id>

# View container logs
docker logs <container-id>

Docker Compose Example

Web app + database + Redis:

version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://user:pass@db:5432/mydb
    depends_on:
      - db
      - redis

  db:
    image: postgres:16
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
    volumes:
      - pgdata:/var/lib/postgresql/data

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

volumes:
  pgdata:
# Start all services
docker compose up -d

# Stop services
docker compose down

# View logs
docker compose logs -f

Docker Use Cases

| Scenario | Description | |----------|------------| | Dev environment | Entire team works in same environment | | CI/CD | Automated testing and deployment | | Microservices | Each service in its own container | | Legacy apps | Isolate old applications | | Demo/prototype | Quick environment setup |

Docker Best Practices

  1. Use small imagesalpine variants
  2. Multi-stage build — Reduce production image size
  3. .dockerignore — Exclude unnecessary files
  4. Non-root user — Don't run as root for security
  5. Layer caching — Copy frequently changing files last
  6. Health check — Monitor container health

Conclusion

Docker is the standard for modern software development and deployment. The days of "it works on my machine" are over. With Docker, your development, testing, and production environments are exactly the same.

If you'd like to build projects with Docker and modern DevOps practices, get in touch: info@cagribilgehan.com. Check out my projects: cagribilgehan.com

İlgili Yazılar

How to Build a SaaS Product: A Starter Guide

What is SaaS, how is it built, and what steps should you follow for a successful SaaS product? Technology selection, pricing, and MVP strategy guide.

No-Code and Low-Code: Build Apps Without Coding

What are no-code and low-code platforms, what are their advantages, and when should you use them? Comparing Bubble, Webflow, Retool, and Airtable.