DEV Community

Cover image for Running Django & Java Apps in Containers — My Docker Week Recap
Vishal
Vishal

Posted on

2

Running Django & Java Apps in Containers — My Docker Week Recap

In my DevOps learning journey, I spent this past week diving into Docker — not just understanding the commands, but applying them in real projects.

This blog summarizes what I built, what I learned, and the small hurdles I faced while containerizing and deploying two full-stack applications.


🚧 What I Tried to Build

I worked on two different projects to get hands-on Docker experience:

  • ✅ A Python Django Web Application
  • ✅ A Java Maven-Based Application

Project -1: Python Django Web Application

🔍 What I Tried to Do

For the first project, I took a basic Django app and containerized it using Docker. My goal was to:

  • Write a Dockerfile that sets up Python, dependencies, and the Django project.
  • Use docker-compose.yml to run both the Django app and a MYSQL database together.
  • Set up a reverse proxy using NGINX to expose the app on a clean port (like 8080).
  • Make sure everything can be started with just one command using docker-compose up.

This project helped me understand how multi-container apps work, how services interact inside a Docker network, and how to troubleshoot startup issues in web apps.

🐞 Issues I Faced

1. Forgot to Add Containers to the Same Network

At first, my app and NGINX couldn’t talk to each other.I didn’t realize that all related containers need to be on the same Docker network to communicate.This tiny thing cost me a lot of time — everything looked okay, but nothing worked until I added the correct network in the docker-compose.yml.

2. Database Connection Problems

My Django app kept throwing errors when trying to connect to MySQL. After a lot of digging, I found out it was due to small things like incorrect hostnames or missing environment variables.One wrong word in the DB settings was enough to break everything.Lesson learned: always double-check your database config.

3. Used Wrong Name in NGINX Config

In the NGINX config, I accidentally used the container name instead of the service name from the Docker Compose file.This gave me “bad gateway” errors. I didn’t know at the time that NGINX looks for the service name, not the container name, when it tries to connect. It seems obvious now, but it wasn’t when I first started — and that’s okay.

✅ How I Solved Them

1. Docker Network Confusion

Now, whenever I write a docker-compose.yml, I make sure that all services are assigned to a common network — even if it seems optional at first.This way, containers can talk to each other smoothly without throwing “connection refused” errors.

Here's a small reminder I use now:

services:
  web:
    ...
    networks:
      - mynetwork
  nginx:
    ...
    networks:
      - mynetwork
networks:
  mynetwork:
Enter fullscreen mode Exit fullscreen mode

2. MySQL Connection Troubles
A small typo in your environment variable (like MYSQL_USER, MYSQL_PASSWORD, or MYSQL_HOST) can ruin your day. I spent hours figuring out that my Django app couldn’t talk to MySQL just because I had a wrong key in the env file. Now I double-check every setting and make sure all configs match between app and database.

3. NGNIX Configuration Issue
In the beginning, I was giving the service name inside the NGINX config, like:

proxy_pass http://service_name:8000;
Enter fullscreen mode Exit fullscreen mode

Which didn’t work.
So I changed it to:

proxy_pass http://container_name:8000;
Enter fullscreen mode Exit fullscreen mode

Here’s how the app looks running inside Docker containers:Containerize the Django App

Project -2: Java Maven-Based Application

🔧 What I Tried to Do (Java Maven App)

After successfully containerizing my Django app, I wanted to push myself a little further — this time by working with a Java-based Maven application. The idea was to set up everything inside Docker and manage it through Docker Compose, just like I did with the Django app.But this project came with its own set of new learning curves. Unlike Python, Java applications involve build steps using Maven, so I had to:

  • Write a custom Dockerfile that builds the app using Maven and then runs the JAR file.
  • Handle MySQL integration inside containers (again), but with a slightly different config structure.
  • Configure NGINX to reverse proxy requests to the Java backend.

Issue I Faced

One of the most confusing parts was figuring out where the database settings were written in the Java Maven project. In Django, it's easy to find — it's in settings.py. But here, I had to dig around the project folders to finally find the right file.
Even after I updated the database details correctly, the app still crashed — and the logs didn’t help much. Everything seemed fine: all containers were running, and the database was connected. But the app just wouldn't work, and there was no clear error telling me what went wrong.
And Issue was like this:

Exception in thread "main" java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at
     com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:108) at 
     com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at
     com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at     
     com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) at 
     com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:444) at
     com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) at
     com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) at
     com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:438) at
     com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:146) at
     com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:119) at
     ConnectionManager.getConnection(ConnectionManager.java:28) at
     Main.main(Main.java:8)
Enter fullscreen mode Exit fullscreen mode

✅ How I Solved It

After spending quite some time googling and going through Stack Overflow posts, I finally discovered that the database configuration was located in a file called application.properties inside the path:

src/main/resources/
Enter fullscreen mode Exit fullscreen mode

This file had keys like:

spring.datasource.url=jdbc:mysql://mysql:3306/expenses_tracker?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=Test@123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Enter fullscreen mode Exit fullscreen mode

So, I added these database credentials under the environment section of the Java service in the docker-compose.yml file.
But… even after that, the app still wouldn’t come up.
Eventually, I found a Stack Overflow post that pointed out an important issue — Java MySQL drivers block public key retrieval by default, which can silently break DB connections.
So, I updated the URL to:

spring.datasource.url=jdbc:mysql://mysql:3306/expenses_tracker?allowPublicKeyRetrieval=true&useSSL=false
Enter fullscreen mode Exit fullscreen mode

Note: Setting allowPublicKeyRetrieval=true is helpful in development environments but can be a security risk in production. Use it with caution.

After making this change and rebuilding the containers, the Java app finally started working! 🎉
Here’s how the app looks running inside Docker containers:

java app

📚 Resources That Helped Me Along the Way

I didn’t figure it all out on my own — these resources were super helpful during the process:

  • 💡 Stack Overflow – For finding answers to weird bugs and errors.
  • 🎥 YouTube Tutorial – To visually understand Docker concepts and how to structure files.
  • 🔍 Google – My go-to for quick searches, Docker docs, and troubleshooting steps.

If you're starting out, I highly recommend using these — they make learning much easier!

🙌 Wrapping Up

This project taught me a lot about how Docker actually works when you're building and running real apps. From setting up services to fixing bugs that didn’t even show clear errors — it was frustrating at times, but also really fun to solve.
I made mistakes, looked things up, and slowly started to understand how all the pieces fit together. And honestly, that’s how real learning happens. If you're just starting out like me — keep going, you're doing great! 😄


❓ Over to You

Have you tried using Docker to run your own apps? Did you also face any weird issues that took hours to figure out?
I’d love to hear your story! Feel free to drop a comment — and let’s connect on X or LinkedIn if you’re also learning Docker, DevOps, or backend stuff.

Thanks for reading - see you in the next blog!

Sentry image

Make it make sense

Make sense of fixing your code with straight-forward application monitoring.

Start debugging →

Top comments (0)

DevCycle image

Fast, Flexible Releases with OpenFeature Built-in

Ship faster on the first feature management platform with OpenFeature built-in to all of our open source SDKs.

Start shipping

👋 Kindness is contagious

Sign in to DEV to enjoy its full potential.

Unlock a customized interface with dark mode, personal reading preferences, and more.

Okay