intermediateSpring Boot Integration: Dockerizing, PostgreSQL, Redis, Kafka & Microservices

Why might a Spring Boot app work fine locally (run from the IDE) but fail to connect to Postgres once containerized?

Running directly on a developer machine, 'localhost' correctly refers to wherever Postgres happens to be running (often a local install or a port-forwarded container). Once the Spring Boot app itself is containerized, 'localhost' refers to the app's own container, not the database's — the connection string must use the database's service/container name (e.g., jdbc:postgresql://db:5432/appdb) so Docker's embedded DNS resolves it correctly.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full DevOps Mastery library.

Why might a Spring Boot app work fine locally (run from the IDE) but fail to connect to Postgres once containerized?

Next Step

Continue to What is the classic Kafka-in-Docker connectivity bug, and how do you fix it?← Back to all Docker questions