Skip to content

Docker Deployment

Radch-enko edited this page Jul 24, 2025 · 2 revisions

Docker Deployment

This document covers the containerized deployment architecture of the Effective Office system using Docker and Docker Compose. It explains the multi-environment setup, container orchestration, and deployment automation processes.

For information about application configuration and environment variables, see [Configuration Management](Configuration Management). For overall system architecture context, see [System Architecture](System Architecture).

Deployment Architecture Overview

The Effective Office system uses Docker Compose to orchestrate multiple services across development and production environments. The deployment strategy separates application logic, database services, and reverse proxy functionality into distinct containers.

docker-deployment.svg

Container Services Configuration

Application Container

The main application runs as a Spring Boot service in a Docker container built from a custom Dockerfile. The container exposes port 8080 and includes comprehensive health monitoring.

Configuration Development Production
Container Name effective-office-app-dev effective-office-app-prod
Port Exposure 8080 8080
Health Check /api/actuator/health /api/actuator/health
Restart Policy unless-stopped unless-stopped

The application container configuration includes:

# From deploy/dev/docker-compose.yml
app:
  build:
    context: .
    dockerfile: Dockerfile
  container_name: effective-office-app-dev
  expose:
    - "8080"
  healthcheck:
    test: [ "CMD", "curl", "-f", "http://localhost:8080/api/actuator/health" ]
    interval: 30s
    timeout: 10s
    retries: 5
    start_period: 40s

Database Container

PostgreSQL 15 Alpine provides the persistence layer with environment-specific port mappings and data volumes.

Configuration Development Production
Container Name effective-office-db-dev effective-office-db-prod
Image postgres:15-alpine postgres:15-alpine
Port Mapping 5433:5432 5432:5432
Volume postgres-data-dev postgres-data-prod

Database health checks ensure service availability:

healthcheck:
  test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ]
  interval: 10s
  timeout: 5s
  retries: 5

Network Architecture

The deployment uses two network configurations to isolate environments and enable external access:

network-architecture.svg

Network configuration from Docker Compose:

networks:
  effective-office-network-dev:
    driver: bridge
  caddy:
    external: true

Automated Deployment Process

The build system provides automated deployment tasks that handle JAR compilation, file transfer, and remote deployment coordination.

deployment-tasks-architecture.svg

Deployment Commands

Development deployment:

./gradlew deployDev -PremoteUser=user -PremoteHost=hostname -PremotePath=/path/to/deploy

Production deployment:

./gradlew deployProd -PremoteUser=user -PremoteHost=hostname -PremotePath=/path/to/deploy

The deployment process executes these steps:

  1. JAR Build: bootJar task creates app-{version}-boot.jar
  2. Local Preparation: Copy JAR to deploy/{env}/ directory
  3. Remote Cleanup: SSH command removes old deployment files
  4. File Transfer: rsync synchronizes local deploy directory to remote server
  5. Container Restart: Docker Compose manages service updates

Reverse Proxy Integration

Caddy serves as the reverse proxy, handling SSL termination and load balancing. The application containers expose port 8080 internally and rely on Caddy labels for external routing.

Caddy Configuration Labels

labels:
  caddy: ${LABEL}
  caddy.reverse_proxy: "{{upstreams 8080}}"

The LABEL environment variable specifies the domain name for external access, while the reverse proxy directive routes traffic to port 8080 on the application container.

Environment Configuration

Environment Variables Structure

The deployment system uses .env files to manage environment-specific configuration:

Variable Purpose Example
POSTGRES_DB Database name effective_office
POSTGRES_USER Database username office_user
POSTGRES_PASSWORD Database password secure_password
SPRING_DATASOURCE_URL Database connection URL jdbc:postgresql://db:5432/effective_office
MIGRATIONS_ENABLE Enable Flyway migrations true
LOG_LEVEL Application log level DEBUG
LABEL Caddy routing domain dev.effective-office.com

Configuration File Locations

  • Development: deploy/dev/.env.example
  • Production: deploy/prod/.env.example

Health Monitoring and Service Dependencies

The deployment implements comprehensive health checking to ensure service reliability:

Application Health Check

healthcheck:
  test: [ "CMD", "curl", "-f", "http://localhost:8080/api/actuator/health" ]
  interval: 30s
  timeout: 10s
  retries: 5
  start_period: 40s

Database Health Check

healthcheck:
  test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ]
  interval: 10s
  timeout: 5s
  retries: 5

Service Dependencies

The application container includes dependency management:

depends_on:
  db:
    condition: service_healthy

This ensures the database is ready before the application starts, preventing connection failures during container startup.

Volume Management

Persistent data storage is handled through named Docker volumes:

Development Environment

  • Volume Name: effective-office-dev-db-data
  • Mount Point: /var/lib/postgresql/data
  • Container: effective-office-db-dev

Production Environment

  • Volume Name: effective-office-prod-db-data
  • Mount Point: /var/lib/postgresql/data
  • Container: effective-office-db-prod

The volume configuration ensures database data persistence across container restarts and updates:

volumes:
  postgres-data-dev:
    name: effective-office-dev-db-data
Clone this wiki locally