🚢 Bank Like a Boss: Dockerize a Spring Boot & MySQL App in 5 Mins! 💰🐳 ( Part 4 )


🌟 Introduction
Welcome back to our Docker journey part 4! In this hands-on guide, we’ll deploy a Spring Boot Banking App with MySQL using Docker. Whether you're a developer or just Docker-curious, we'll break it down step by step!
We'll explain each step clearly — perfect for both tech-savvy and non-tech readers.
📥 Step 1: Clone the Project
git clone https://github.com/abhishek26w/Springboot-BankApp.git
cd Springboot-BankApp
🔍 What’s Inside?
README.md
: Explains the app’s features, setup, and environment variables.application.properties
: Database configurations (checksrc/main/resources/
).(Pro Tip: Always read the README first!)
🧱 Step 2: Dockerfile Basic
(Simple Version)
# Use Java base image
FROM openjdk:17
# App directory
WORKDIR /app
# Copy source code
COPY . .
# Build the project
RUN mvn clean install -DskipTests=true
# Expose app port
EXPOSE 8080
# Run the app
ENTRYPOINT ["java", "-jar", "target/bankapp.jar"]
👉 This will create a larger image because it copies source code and dependencies.
🪄 Step 3: Why Use Maven & Clean Install?
mvn
is the build tool for Java apps.mvn clean install
cleans old builds & compiles a fresh one.-DskipTests=true
skips running test files to speed up build.
📌 Main code vs test code?
src/main/java
→ actual app logicsrc/test/java
→ test files (for checking bugs)
🧰 Step 4: Multi-Stage Dockerfile ( Optimized Image )
# -------------Stage 1 - Build----------------
FROM maven:3.8.5-openjdk-17 AS build
WORKDIR /app
COPY . .
RUN mvn clean install -DskipTests=true
# --------------Stage 2 - Run-----------------
FROM openjdk:17-jdk-slim
WORKDIR /app
COPY --from=build /app/target/bankapp.jar bankapp.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "bankapp.jar"]
✅ This creates a smaller image by excluding Maven and source files in the final image.
CMD vs Entrypoint
CMD | Entrypoint |
Default Command | App start command |
Can be overridden | More strict and fixed |
🕸️ Step 5: Docker Network & Manual Run
1️⃣Create Docker network:
docker network create -d bridge bankapp
2️⃣Run MySQL:
docker run -itd --name mysql -e MYSQL_ROOT_PASSWORD=Test@123 -e MYSQL_DATABASE=bankdb --network bankapp mysql:latest
3️⃣Run Spring Boot app::
docker run -itd --name bankapp \
-e SPRING_DATASOURCE_USERNAME=root \
-e SPRING_DATASOURCE_PASSWORD=Test@123 \
-e SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/bankdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC \
--network bankapp -p 8080:8080 \
bankapp
✔️ Now check the app in your browser:
👉http://<your-public-ip>:8080
📦 Docker Compose:
docker-compose.yml
:
version: "3.8"
services:
mysql:
image: mysql:latest
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: Test@123
MYSQL_DATABASE: bankdb
networks:
- bankapp
volumes:
- mysql-data:/var/lib/mysql
restart: always
bankapp:
image: heyitsmeabhishek/bankapp
container_name: bankapp
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: Test@123
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/bankdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
depends_on:
- mysql
networks:
- bankapp
volumes:
mysql-data:
networks:
bankapp:
Run the stack:
docker compose up
/ docker compose up -d
( Detached mode )
Stop the stack:
docker compose down
Bonus: Inspect MySQL Container:
docker exec -it mysql bash
mysql -u root -p # Password: Test@123
USE bankdb;
SHOW TABLES;
SELECT * FROM account;
SELECT * FROM Transaction;
exit
exit
🔜 What’s Next?
Stay tuned for Part 5, where we’ll dive into Docker Security (Scout) and Docker PAT (Personal Access Tokens)! 🛡️
📌 Key Takeaways
✔️ Multi-stage builds = smaller images.
✔️ Docker networks enable seamless container communication.
✔️ Compose simplifies multi-container setups.
💬 Got questions? Drop them below! Happy Dockering! 🐳
( Code/Files: GitHub Repo: git clone https://github.com/abhishek26w/Springboot-BankApp.git )
Subscribe to my newsletter
Read articles from ABHISHEK WAGHMARE directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

ABHISHEK WAGHMARE
ABHISHEK WAGHMARE
An Introduction To DevOps: Where Development And Operations Meet 🔍 My DevOps learner journey has been inspired by a true passion for continual personal development and a genuine curiosity for cloud and automation technologies. With the practice of engaging in numerous online coursework and community threads, I have built a growing comprehension of what is necessary for everyday life in the tools offered from Docker, Jenkins, and Kubernetes, which are mandatories in the IT Society. 🛠 What sets me apart? A commitment to practical application. Through personal projects, I actively implement my learning to solve real-world problems, gaining hands-on experience. This proactive approach helps me not only understand technologies at a surface level but to deeply integrate them into effective solutions. My ultimate goal? To merge innovative DevOps practices with business objectives to streamline operations and boost productivity in any tech landscape. I am eager to bring my fresh perspective and evolving expertise to a vibrant team, where continuous learning is intertwined with company growth. 📨 Let’s connect and explore how we can drive progress together in the fascinating world of DevOps!