Explain Docker Compose File https://github.com/stacksimplify/devops-real-world-project-implementation-on-aws/blob/main/04_Docker_Compose/docker-compose.yaml
🔷 1. Basic Info name: retail-sample
👉 Project name (used as prefix for containers, network, etc.)
🔷 2. Network networks: default: name: retail-sample_default
👉 Creates a custom Docker network
✔ All services talk using service name (DNS) Example:
catalog → accessible as http://catalog:8080 orders-db → orders-db:5432 🔷 3. Services (Main Part)
Each service = one container
🛒 3.1 cart service
👉 Handles shopping cart
Key points: Depends on: depends_on: carts-db: condition: service_healthy
✔ Waits until DB is healthy
Environment: RETAIL_CART_PERSISTENCE_PROVIDER=dynamodb RETAIL_CART_PERSISTENCE_DYNAMODB_ENDPOINT=http://carts-db:8000
✔ Uses DynamoDB (local container)
Security: cap_drop: all cap_add: NET_BIND_SERVICE read_only: true
✔ Minimal privileges (DevOps best practice)
Healthcheck: curl http://localhost:8080/actuator/health
✔ Docker checks if service is alive
🗄️ 3.2 carts-db image: amazon/dynamodb-local:1.20.0
👉 Local DynamoDB (no AWS needed)
✔ Used by cart service
📦 3.3 catalog
👉 Product listing service
Uses: RETAIL_CATALOG_PERSISTENCE_PROVIDER=mysql
✔ Connected to MySQL (MariaDB container)
🗄️ 3.4 catalog-db image: mariadb:10.9
👉 MySQL database
Env: MYSQL_DATABASE=catalogdb MYSQL_USER=catalog_user
✔ Creates DB + user automatically
💳 3.5 checkout
👉 Handles checkout process
Uses: RETAIL_CHECKOUT_PERSISTENCE_PROVIDER=redis
✔ Uses Redis (fast cache)
⚡ 3.6 checkout-redis image: redis:6.0-alpine
👉 In-memory DB for checkout
📑 3.7 orders
👉 Handles orders
Uses: PostgreSQL → DB RabbitMQ → messaging RETAIL_ORDERS_MESSAGING_PROVIDER=rabbitmq
✔ Event-driven architecture
🗄️ 3.8 orders-db image: postgres:16.1
👉 PostgreSQL DB
🐰 3.9 rabbitmq image: rabbitmq:3-management
👉 Message broker
✔ Used for async communication
🌐 3.10 ui (Frontend)
👉 Main entry point
Port mapping: ports:
- 8888:8080
✔ Access app on:
http://:8888 Depends on all services: cart, catalog, checkout, orders
✔ UI starts only when all backend services are healthy
🔷 4. Common Concepts (Important) 🔹 depends_on
✔ Controls startup order ✔ Waits for service health
🔹 healthcheck
✔ Docker checks service status ✔ Used for dependency readiness
🔹 environment
✔ Pass config to container ✔ DB connection, endpoints, etc.
🔹 restart: always
✔ Auto restart if container stops
🔹 read_only + tmpfs
✔ Security hardening ✔ Prevents filesystem modification
🔹 cap_drop / cap_add
✔ Linux capabilities control ✔ Reduce attack surface
🔥 How to run docker compose up -d Check: docker ps docker compose logs -f 🎯 Interview Answer (Short)
This is a microservices-based Docker Compose setup with multiple services like cart, catalog, orders, and UI. Each service uses its own database (DynamoDB, MySQL, Redis, PostgreSQL) and communicates over a shared network using service names. Health checks and depends_on ensure proper startup order, and security is enforced using read-only filesystems and dropped Linux capabilities.
