version: "3.8"
services:
postgres:
image: postgres:15-alpine
environment:
POSTGRES_DB: testdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U testuser -d testdb"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
web-api:
image: nginx:alpine
ports:
- "8080:80"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
app-with-waitup:
image: alpine:latest
depends_on:
- postgres
- redis
- web-api
command: |
sh -c "
# Install waitup (in real usage, you'd use the waitup image)
echo 'Simulating waitup checking dependencies...'
sleep 2
echo 'Dependencies ready! Starting application...'
sleep 10
echo 'Application running...'
"
waitup-example:
build:
context: .
dockerfile: Dockerfile
command: |
postgres:5432
redis:6379
web-api:80
--timeout 60s
--interval 2s
--verbose
--
echo "All services are ready! Application can start now."
depends_on:
- postgres
- redis
- web-api
waitup-http:
build:
context: .
dockerfile: Dockerfile
command: |
https://httpbin.org/status/200
--expect-status 200
--timeout 30s
--json
profiles:
- http-example
waitup-any:
build:
context: .
dockerfile: Dockerfile
command: |
postgres:5432
backup-postgres:5432
--any
--timeout 30s
--verbose
--
echo "At least one database is available!"
depends_on:
- postgres
profiles:
- failover-example
networks:
default:
driver: bridge
volumes:
postgres_data:
driver: local
redis_data:
driver: local