Day 22 of 90 Days of DevOps Challenge: containerizing SpringBoot and Python App


Yesterday, I explored how to dockerize web applications, learned the purpose of Dockerfiles, and understood how Docker images help in building portable, lightweight containers for any environment. It was quite exciting to see my app up and running inside a container!
Today’s sneak peek was even more hands-on I focused on Dockerizing Java Spring Boot and Python Flask applications. Here's a quick walkthrough of what I did:
Dockerizing Java Spring Boot Application
Spring Boot applications are typically packaged as .jar
files, and we can run them using the java -jar
command. When a Spring Boot app runs, it spins up an embedded Tomcat server (usually on port 8080
).
Dockerfile for Spring Boot App:
FROM openjdk:17
MAINTAINER ZerotoRoot
COPY target/app.jar /usr/app/
WORKDIR /usr/app/
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
Steps to Dockerize:
# Clone the Git repo
$ git clone https://github.com/ashokitschool/spring-boot-docker-app.git
$ cd spring-boot-docker-app
# Build the jar file using Maven
$ mvn clean package
# Build Docker image
$ docker build -t sb-app .
# Run Docker container
$ docker run -d -p 8080:8080 sb-app
# Check container logs
$ docker logs <container-id>
Access your Spring Boot application at: http://localhost:8080/
(or host VM IP with port 8080)
Dockerizing Python Flask Application
Unlike Java, Python apps don’t require any build tools. You can run them directly using:
python app.py
Flask is a micro web framework in Python used to create REST APIs. All dependencies are typically listed in a requirements.txt
file.
Dockerfile for Python Flask App:
FROM python:3.6
MAINTAINER ZerotoRoot
COPY . /usr/app/
WORKDIR /usr/app/
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python", "app.py"]
Steps to Dockerize:
# Clone the Git repo
$ git clone https://github.com/ashokitschool/python-flask-docker-app.git
$ cd python-flask-docker-app
# Build Docker image
$ docker build -t flask-app .
# Run Docker container
$ docker run -d -p 5000:5000 flask-app
# Check running containers
$ docker ps
Note: Ensure port 5000 is allowed in your cloud VM’s inbound rules.
Access flask app using: http://<public-ip>:5000/
Final Thoughts
Today was all about hands-on Docker practice. From compiling a Spring Boot app into a .jar
, building its Docker image, and launching it, to setting up a lightweight Python Flask API I learned how Docker makes development and deployment so much smoother!
Excited for what tomorrow brings in this DevOps journey!
Subscribe to my newsletter
Read articles from Vaishnavi D directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
