Order service crash-loops on startup only in Docker Compose, never when run locally from the IDE
The Spring Boot app connects fine to Postgres when run from IntelliJ against a container started separately, but crash-loops with connection refused when the whole stack is started together via docker compose up. Diagnose. Expected reasoning: when run from the IDE, the developer likely has the connection string pointed at localhost:5432 (a port-mapped container), which is valid in that specific context. Inside Compose, the app container itself needs to resolve the database by service name (db), not localhost, since the app and database are now both containers on the same project network with n
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response