Skip to main content
StreamLine Logistics uses Docker Compose to orchestrate all microservices and their dependencies. This guide explains the Docker setup in detail.

Docker Compose Overview

The project uses a single docker-compose.yml file that defines:
  • 3 microservices (Order, Inventory, Tracking)
  • 1 service discovery server (Eureka)
  • 3 databases (PostgreSQL, MySQL, MongoDB)
  • 1 custom bridge network
  • 3 persistent volumes

Architecture

Complete Docker Compose Configuration

Here’s the complete docker-compose.yml from the project:
services:
  eureka-server:
    container_name: eureka-server
    build:
      context: .
      dockerfile: ./microservice-eureka/Dockerfile
    image: eureka-service:latest
    ports:
      - "8761:8761"
    networks:
      - microservices-network
    
  order-service:
    container_name: order-service
    build:
      context: .
      dockerfile: ./microservice-order/Dockerfile
    image: order-service:latest
    ports:
      - "8090:8090"
    networks:
      - microservices-network
    depends_on:
      - eureka-server
  
  inventory-service:
    container_name: inventory-service
    build:
      context: .
      dockerfile: ./microservice-inventory/Dockerfile
    image: inventory-service:latest
    ports: 
      - "9090:9090"
    networks:
      - microservices-network
    depends_on:
      - eureka-server
  
  tracking-service:
    container_name: tracking-service
    build:
      context: .
      dockerfile: ./microservice-tracking/Dockerfile
    image: tracking-service:latest
    ports:
      - "8091:8091"
    networks:
      - microservices-network
    depends_on:
      - eureka-server
  
  order-db:
    container_name: order_db
    image: postgres:15
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: orderdb
    ports:
      - "5432:5432"
    networks:
      - microservices-network
    volumes:
      - orderdb-data:/var/lib/postgresql/data

  inventory-db:
    container_name: inventory_db
    image: mysql:8
    restart: always
    environment:
      MYSQL_ROOT_USER: root
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: inventorydb
    ports:
      - "3306:3306"
    networks:
      - microservices-network
    volumes:
      - inventorydb-data:/var/lib/mysql
  
  traking-db:
    container_name: tracking_db
    image: mongo:latest
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: password
    ports:
      - "27017:27017"
    networks:
      - microservices-network
    volumes:
      - trackingdb-data:/data/db

networks:
  microservices-network:
    driver: bridge

volumes:
  orderdb-data:
  inventorydb-data:
  trackingdb-data:

Service Breakdown

Eureka Server

Service discovery and registration server.
eureka-server:
  container_name: eureka-server
  build:
    context: .
    dockerfile: ./microservice-eureka/Dockerfile
  image: eureka-service:latest
  ports:
    - "8761:8761"
  networks:
    - microservices-network
Key Points:
  • Runs on port 8761
  • No dependencies (starts first)
  • Dashboard accessible at http://localhost:8761
  • All other services register with this instance

Order Service

Handles order management operations.
order-service:
  container_name: order-service
  build:
    context: .
    dockerfile: ./microservice-order/Dockerfile
  image: order-service:latest
  ports:
    - "8090:8090"
  networks:
    - microservices-network
  depends_on:
    - eureka-server
Key Points:
  • Runs on port 8090
  • Depends on Eureka Server
  • Uses PostgreSQL database (order_db)
  • Connects to database at order_db:5432

Inventory Service

Manages inventory and stock levels.
inventory-service:
  container_name: inventory-service
  build:
    context: .
    dockerfile: ./microservice-inventory/Dockerfile
  image: inventory-service:latest
  ports: 
    - "9090:9090"
  networks:
    - microservices-network
  depends_on:
    - eureka-server
Key Points:
  • Runs on port 9090
  • Depends on Eureka Server
  • Uses MySQL database (inventory_db)
  • Connects to database at inventory_db:3306
  • Includes OpenAPI/Swagger documentation

Tracking Service

Tracks shipment status and location.
tracking-service:
  container_name: tracking-service
  build:
    context: .
    dockerfile: ./microservice-tracking/Dockerfile
  image: tracking-service:latest
  ports:
    - "8091:8091"
  networks:
    - microservices-network
  depends_on:
    - eureka-server
Key Points:
  • Runs on port 8091
  • Depends on Eureka Server
  • Uses MongoDB database (tracking_db)
  • Connects to database at tracking_db:27017

Database Configuration

PostgreSQL (Order Database)

order-db:
  container_name: order_db
  image: postgres:15
  restart: always
  environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: password
    POSTGRES_DB: orderdb
  ports:
    - "5432:5432"
  networks:
    - microservices-network
  volumes:
    - orderdb-data:/var/lib/postgresql/data
Configuration:
  • Image: PostgreSQL 15
  • Database: orderdb
  • User: postgres
  • Password: password
  • Port: 5432
  • Volume: orderdb-data (persistent storage)
Change the default password in production environments.

MySQL (Inventory Database)

inventory-db:
  container_name: inventory_db
  image: mysql:8
  restart: always
  environment:
    MYSQL_ROOT_USER: root
    MYSQL_ROOT_PASSWORD: password
    MYSQL_DATABASE: inventorydb
  ports:
    - "3306:3306"
  networks:
    - microservices-network
  volumes:
    - inventorydb-data:/var/lib/mysql
Configuration:
  • Image: MySQL 8
  • Database: inventorydb
  • Root User: root
  • Root Password: password
  • Port: 3306
  • Volume: inventorydb-data (persistent storage)

MongoDB (Tracking Database)

traking-db:
  container_name: tracking_db
  image: mongo:latest
  restart: always
  environment:
    MONGO_INITDB_ROOT_USERNAME: root
    MONGO_INITDB_ROOT_PASSWORD: password
  ports:
    - "27017:27017"
  networks:
    - microservices-network
  volumes:
    - trackingdb-data:/data/db
Configuration:
  • Image: MongoDB latest
  • Root Username: root
  • Root Password: password
  • Port: 27017
  • Volume: trackingdb-data (persistent storage)
Note the typo in the service name: traking-db should be tracking-db.

Networking

Bridge Network

networks:
  microservices-network:
    driver: bridge
All services run on a custom bridge network named microservices-network. This allows:
  • Container-to-container communication using container names
  • Isolated network from other Docker containers
  • DNS resolution for service discovery
Example: Order Service connects to PostgreSQL using hostname order_db instead of localhost.

Persistent Volumes

volumes:
  orderdb-data:
  inventorydb-data:
  trackingdb-data:
Docker volumes ensure data persistence across container restarts:
VolumeDatabasePurpose
orderdb-dataPostgreSQLStores order data
inventorydb-dataMySQLStores inventory data
trackingdb-dataMongoDBStores tracking data

Managing Volumes

docker volume ls | grep streamline

Docker Commands Reference

Starting Services

docker compose up -d

Stopping Services

docker compose stop

Monitoring Services

docker compose logs -f

Service Management

docker compose restart order-service

Dockerfile Examples

While the complete Dockerfiles are in each microservice directory, they typically follow this pattern:
FROM eclipse-temurin:17-jdk-alpine

WORKDIR /app

COPY microservice-*/target/*.jar app.jar

EXPOSE <port>

ENTRYPOINT ["java", "-jar", "app.jar"]

Environment-Specific Configurations

Development Environment

For local development, you might want to modify docker-compose.yml:
order-service:
  # ... other config
  environment:
    - SPRING_PROFILES_ACTIVE=dev
  volumes:
    - ./microservice-order/src:/app/src  # Hot reload

Production Environment

Create a separate docker-compose.prod.yml:
services:
  order-db:
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}  # Use secrets
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 512M
Use with:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Troubleshooting

Container Won’t Start

# Check container logs
docker compose logs <service-name>

# Check container status
docker compose ps -a

# Inspect container
docker inspect <container-name>

Network Issues

# List networks
docker network ls

# Inspect network
docker network inspect microservices-network

# Recreate network
docker compose down
docker network prune
docker compose up -d

Volume Issues

# Check volume mounts
docker inspect <container-name> | grep -A 10 Mounts

# Clean unused volumes
docker volume prune

Database Connection Issues

# Test PostgreSQL connection
docker compose exec order-service nc -zv order_db 5432

# Test MySQL connection
docker compose exec inventory-service nc -zv inventory_db 3306

# Test MongoDB connection
docker compose exec tracking-service nc -zv tracking_db 27017

Performance Optimization

Resource Limits

Add resource constraints to prevent any service from consuming too many resources:
order-service:
  # ... other config
  deploy:
    resources:
      limits:
        cpus: '1.0'
        memory: 1G
      reservations:
        cpus: '0.5'
        memory: 512M

Health Checks

Add health checks for better orchestration:
order-service:
  # ... other config
  healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:8090/actuator/health"]
    interval: 30s
    timeout: 10s
    retries: 3
    start_period: 40s

Next Steps

  • Review Configuration for detailed service configuration
  • Learn about customizing environment variables
  • Explore production deployment strategies

Build docs developers (and LLMs) love