Quand une équipe dit : Sur mon PC ça marche… mais pas en prod !
c’est souvent parce que :
Docker sert à standardiser, tout simplement
On veut lancer :
Avec une seule commande :
docker compose up -d
FROM maven:3.9-eclipse-temurin-17 AS build WORKDIR /app COPY pom.xml . RUN mvn dependency:go-offline COPY src ./src RUN mvn package -DskipTests
Puis exécution :
FROM eclipse-temurin:17-jre WORKDIR /app COPY --from=build /app/target/*.jar app.jar ENTRYPOINT ["java","-jar","app.jar"]
services: db: image: postgres:16-alpine environment: POSTGRES_DB: wouaf POSTGRES_USER: wouaf POSTGRES_PASSWORD: wouaf ports: - "5432:5432" healthcheck: test: ["CMD-SHELL", "pg_isready -U wouaf -d wouaf"] interval: 5s timeout: 5s retries: 10 api: build: . ports: - "8080:8080" environment: SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/wouaf SPRING_DATASOURCE_USERNAME: wouaf SPRING_DATASOURCE_PASSWORD: wouaf depends_on: db: condition: service_healthy
depends_on
Parce que depends_on :
Avec un healthcheck, on attend réellement la disponibilité !
healthcheck
docker compose up -d docker compose logs -f api
Puis :
curl http://localhost:8080/actuator/health
/actuator/health