DEV Community

Cover image for πŸš€ How I Dockerized My Java Spring Boot App and Deployed It on AWS EC2
Abhishek Jha
Abhishek Jha

Posted on

πŸš€ How I Dockerized My Java Spring Boot App and Deployed It on AWS EC2

Hey everyone! πŸ‘‹

I recently completed a project that really leveled up my understanding of DevOps, Java backend development, and cloud deployment β€” and I wanted to share my experience in case you're starting your journey or exploring similar tools.

I built and deployed a full-stack Expenses Tracker Web App, where I used technologies like Spring Boot, Docker, Docker Compose, and AWS EC2. It’s the first time I’ve dockerized a real-world application and deployed it on a live server, and it taught me a ton about backend systems, containerization, and cloud environments.

Let me walk you through the journey, what I built, how I deployed it, the challenges I faced, and what I learned.

🧾 Project Overview: Expenses Tracker Web App

The goal was to create a simple but functional expense tracking system where users could:

  • Register and log in securely
  • Add, view, and delete their expenses
  • View a summary of their spending

πŸ› οΈ Technologies I Used

This project brought together several technologies across development and deployment:

  • Java and Spring Boot (core application logic)
  • Spring Security (for authentication)
  • Spring Data JPA + MySQL (for database integration)
  • Thymeleaf + Bootstrap (for frontend templating and styling)
  • Docker & Docker Compose (for containerization)
  • Amazon EC2 (Ubuntu) (for hosting the app)

Each of these played a key role in building a complete, modular, and scalable web application.

🐳 Dockerizing the Application

One of my main goals was to learn how to containerize a Java application using Docker. I created a Dockerfile that builds and runs the Spring Boot app, and used Docker Compose to spin up both the application and a MySQL database together in isolated containers.

This approach makes the app environment-independent and super easy to run on any server or system that supports Docker.

It also taught me how important it is to properly handle environment variables (like DB connection strings) for cleaner config management and better security.

☁️ Deploying on AWS EC2

Once my app was running smoothly in Docker locally, I moved to the cloud.

I launched an EC2 Ubuntu instance on AWS and installed Docker and Docker Compose. After pushing my project to GitHub, I cloned it into the EC2 server and ran everything using Docker Compose. I also configured AWS security groups to allow traffic on the correct ports.

In just a few steps, I had a live server running my app β€” all from the cloud. It felt amazing to see something I built locally available on a public IP address for the world to access.

🧩 A Problem I Faced (and Solved)

One interesting challenge I faced while working with Docker Compose was related to service-to-service communication.

At first, my Spring Boot app couldn’t connect to the MySQL container. After digging in, I realized the issue was that I was trying to connect using localhost instead of the Docker service name defined in the Compose file.

Once I changed the database hostname to match the service name (mysql in my case), the connection worked perfectly. It was a small but valuable lesson about how Docker networking works in multi-container setups.

πŸ“š What I Learned

This project gave me hands-on experience with several critical concepts and tools that are extremely relevant in real-world software development:

  • βœ… How to containerize a full-stack Java web application using Docker

  • βœ… How to write and structure a Docker Compose file for multi-container setups

  • βœ… The importance of environment variables and clean configuration

  • βœ… How to launch and configure an EC2 instance on AWS

  • βœ… Managing cloud infrastructure (ports, SSH, Docker setup)

  • βœ… Debugging common DevOps and deployment issues

Most importantly, it taught me how to go from idea ➝ working app ➝ running cloud deployment β€” something I can now repeat and improve on with future projects.

πŸ”— Check Out the Project

The full source code is available on my GitHub:
πŸ‘‰ Dockerized-Expenses-Tracker-WebApp

Feel free to explore the code, run it yourself, or reach out if you have questions!

🎯 What’s Next?

I'm excited to keep building and improving. Here are a few things I want to work on next:

  • Add an Nginx reverse proxy for better scalability and HTTPS support

  • Explore CI/CD with GitHub Actions

  • Try PostgreSQL as an alternative DB engine

  • Learn about Kubernetes for orchestrating containers at scale

  • Create a frontend container and host both under a single domain

🧠 Final Thoughts

If you're just starting out with Docker, Java, or AWS, my advice is simple: build something real. You'll hit problems. You’ll read docs. You’ll break things. And then, you'll fix them β€” and learn deeply from the process.

Thanks for reading! If you enjoyed this, found it helpful, or have questions, feel free to:

  • πŸ’¬ Leave a comment

  • 🧑 React to this post

Let’s keep building, breaking, and learning πŸš€

Top comments (2)

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

Pretty cool you got it all up and running on EC2. Been cool seeing steady progress - it adds up. what do you think actually keeps things growing over time? habits? luck? just showing up?

Collapse
 
abhishek365 profile image
Abhishek Jha

Thanks a lot! πŸ™Œ I think it’s mostly about showing up consistently and staying curious. Habits help, and a bit of luck sometimes too β€” but steady effort really adds up over time.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.