Performance: docker-compose for services
This affects the startup time and resource usage of multiple backend services running together, impacting initial load and responsiveness.
version: '3.8' services: service1: build: ./service1 ports: - "8080:8080" service2: build: ./service2 ports: - "8081:8081" depends_on: service1: condition: service_healthy healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"] interval: 10s retries: 5
version: '3.8' services: service1: build: ./service1 ports: - "8080:8080" service2: build: ./service2 ports: - "8081:8081" depends_on: - service1 command: ./wait-for-it.sh service1:8080 -- java -jar app.jar
| Pattern | Container Startup | Blocking | Resource Usage | Verdict |
|---|---|---|---|---|
| Sequential wait-for-it script | Serial startup | Blocks dependent services | Higher due to idle wait | [X] Bad |
| Healthcheck with depends_on | Parallel startup | Non-blocking | Efficient resource use | [OK] Good |
docker-compose with Spring Boot services?docker-compose.yml file?ports: - "hostPort:containerPort".docker-compose.yml snippet:services:
app:
image: springboot-app
ports:
- "8080:8080"
depends_on:
- db
db:
image: postgres
environment:
POSTGRES_PASSWORD: exampledocker-compose up?docker-compose.yml but your Spring Boot app fails to connect to the database:services:
app:
image: springboot-app
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/mydb
db:
image: postgres
environment:
POSTGRES_PASSWORD: exampledocker-compose. You want the database to keep data even if the container stops. Which snippet correctly adds persistent storage for the database?db-data:/var/lib/mysql.volumes: with the same name.Pass the test and this pattern moves unknown