spring-petclinic/docker-compose.yml
Bhavesh Khandelwal bdbece8d3f Improve Docker and CI/CD configuration with best practices
- Dockerfile: Add non-root user, healthcheck, optimized layer caching
- docker-compose.yml: Add healthchecks, data volumes, networking, better configuration
- CI/CD: Add multi-platform builds, image testing, multiple tags, metadata
- .dockerignore: Comprehensive exclusions for faster builds

These improvements enhance security, reliability, and maintainability
following Docker and Spring Boot best practices.

Signed-off-by: Bhavesh Khandelwal <bhaveshkhandelwal1232@gmail.com>
2025-12-17 10:42:17 +05:30

83 lines
2.4 KiB
YAML

services:
app:
build:
context: .
dockerfile: Dockerfile
image: spring-petclinic:latest
container_name: spring-petclinic-app
ports:
- "8080:8080"
environment:
SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-mysql}
SPRING_DATASOURCE_URL: ${SPRING_DATASOURCE_URL:-jdbc:mysql://mysql:3306/petclinic?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC}
SPRING_DATASOURCE_USERNAME: ${SPRING_DATASOURCE_USERNAME:-petclinic}
SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD:-petclinic}
depends_on:
mysql:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- petclinic-network
mysql:
image: mysql:9.2
container_name: spring-petclinic-mysql
ports:
- "${MYSQL_PORT:-3306}:3306"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
MYSQL_USER: ${SPRING_DATASOURCE_USERNAME:-petclinic}
MYSQL_PASSWORD: ${SPRING_DATASOURCE_PASSWORD:-petclinic}
MYSQL_DATABASE: ${MYSQL_DATABASE:-petclinic}
MYSQL_ALLOW_EMPTY_PASSWORD: "false"
volumes:
- mysql-data:/var/lib/mysql
- "./conf.d:/etc/mysql/conf.d:ro"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-root}"]
interval: 10s
timeout: 5s
retries: 10
start_period: 20s
restart: unless-stopped
networks:
- petclinic-network
postgres:
image: postgres:18.0
container_name: spring-petclinic-postgres
ports:
- "${POSTGRES_PORT:-5432}:5432"
environment:
POSTGRES_PASSWORD: ${SPRING_DATASOURCE_PASSWORD:-petclinic}
POSTGRES_USER: ${SPRING_DATASOURCE_USERNAME:-petclinic}
POSTGRES_DB: ${POSTGRES_DB:-petclinic}
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${SPRING_DATASOURCE_USERNAME:-petclinic}"]
interval: 10s
timeout: 5s
retries: 10
start_period: 20s
restart: unless-stopped
profiles:
- postgres
networks:
- petclinic-network
volumes:
mysql-data:
driver: local
postgres-data:
driver: local
networks:
petclinic-network:
driver: bridge