Docker Mastery Part 4: Real-World Scenarios and Microservices

Apply your knowledge to real-world scenarios. We'll setup a full-stack Web App with a Database and explore Microservices architecture.

FSI
Full Stack Insights
2 min read...

Introduction

Theory is good, but practice is better. In this part, we will look at two common architectural patterns: a Monolithic Web App with a Database, and a Microservices setup.

Scenario 1: Web App + PostgreSQL

This is the most common setup for full-stack developers.

version: '3.8'

services:
  api:
    build: ./api
    ports:
      - "5000:5000"
    environment:
      - DB_HOST=db
      - DB_USER=postgres
      - DB_PASS=password
    depends_on:
      - db

  client:
    build: ./client
    ports:
      - "3000:80" # Nginx serving React
    depends_on:
      - api

  db:
    image: postgres:13-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: myappdb
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

Why this works:

  • Isolation: The database runs in its own clean environment.
  • Networking: The api service can reach the db service simply by using the hostname db. Docker handles the internal DNS.

Scenario 2: Microservices

In a microservices architecture, you might have separate services for Auth, Billing, and Notifications.

version: '3.8'

services:
  auth-service:
    build: ./services/auth
    networks:
      - backend

  billing-service:
    build: ./services/billing
    networks:
      - backend

  api-gateway:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    networks:
      - backend
      - frontend

networks:
  backend:
    driver: bridge
  frontend:
    driver: bridge

Key Takeaway:

Docker Compose creates a default network where all services can talk to each other. However, defining custom networks (like backend vs frontend) provides better isolation and security.

Summary

Whether you are running a simple blog or a complex distributed system, Docker provides the tools to replicate the architecture locally with ease. Finally, in Part 5: Advanced Patterns, we will cover optimization, security, and advanced networking.

Share this article:

Related Articles

FSI

Full Stack Insights

Software Engineer

Passionate about software development, architecture, and sharing knowledge with the community.