🧠 Real-world lesson as a junior Java developer After a month of running perfectly, my Spring Boot app suddenly stopped working. The logs showed: java.sql.SQLNonTransientConnectionException: Socket fail to connect to host: localhost:3307 After hours of debugging, I realized the real issue wasn’t the database — it was Docker networking. Inside a container, localhost doesn’t point to the VM — it points to the container itself. 😅 💡 What I learned and fixed: Connected Spring Boot container to the correct Docker network Changed DB URL from localhost to db: jdbc:mariadb://db:3306/insurance_app Split configs into: application-properties application-local-properties application-prod-properties Used spring.profiles.active=prod for the right environment 🚀 Result: The app is up again — and I learned how critical Spring profiles, Docker networks, and environment separation are. A small crash turned into a big lesson. 💪 #Java #SpringBoot #Docker #Backend #LearningByDoing #DeveloperJourney
A common mistake when people are new to working with networks in Docker... Docker sees the localhost as its own container, which makes sense. To communicate with an application running in another container, you need to call it by the container name.
Very good post peter keep it up. Learning is beautiful, and we have a great profession to do it. Make it sound more human though! Or not, what do I know 😅
Thnx for sharing!
i personally find this type of issues most rewarding to solve
I have also faced this issue in my personal project 🙃🙃
If it was running one month perfectly something was changed so that it did not run anymore. What changed?