π Dockerized Flask App Deployment via Jenkins CI/CD on Localhost

Table of contents
- π§ Introduction
- π§ What I Built
- π§° Tech Stack
- π File Structure
- π‘ The Flask App (app.py)
- π³ Dockerfile
- βοΈ Jenkinsfile (CI/CD Pipeline) - get it from github -https://github.com/HARSHITHA-G-M/Automate-Docker-Image-Creation-and-Deployment-using-Jenkins-Pipeline.git
- π΅βπ« Errors I Faced (and Fixed)
- β Jenkins service failed to start
- β Final Output
- π Key Takeaways
- π§ Lesson You Learned (and Should Highlight in Blog/LinkedIn)

Automate Docker image creation and deployment for a Python Flask app using Jenkins pipelines, built from scratch on WSL2.
π§ Introduction
As part of my DevOps learning journey, I decided to take on a real-world automation challenge:
π Build a Jenkins pipeline from scratch to deploy a Dockerized Flask app on localhost!
βAutomate Docker Image Creation and Deployment using Jenkins Pipeline β no pre-built images allowed.β
π§ What I Built
β Project Overview
Build a Flask app Docker image
Automate the entire process using Jenkins pipeline
Expose the container at
localhost:5000
Push image to self-hosted registry (optional)
π§° Tech Stack
Tool | Purpose |
π Python/Flask | Lightweight web application |
π³ Docker | Containerization |
π§± Jenkins | CI/CD pipeline automation |
π§ Ubuntu WSL2 | Local DevOps lab setup |
π File Structure
π¦ flask-docker-jenkins/
β£ π app/
β β π app.py
β£ π Dockerfile
β£ π Jenkinsfile
π‘ The Flask App (app.py)
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "β
Hello from Flask App via Docker + Jenkins!"
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000)
π³ Dockerfile
FROM python:3.9
WORKDIR /app
COPY ./app /app
RUN pip install -r requirements.txt
CMD ["python3", "app.py"]
βοΈ Jenkinsfile (CI/CD Pipeline) - get it from github -https://github.com/HARSHITHA-G-M/Automate-Docker-Image-Creation-and-Deployment-using-Jenkins-Pipeline.git
π΅βπ« Errors I Faced (and Fixed)
β Jenkins service failed to start
β Fixed by installing correct Java version:
sudo apt install openjdk-17-jdk -y
β App not showing at localhost:5000
β
Realized Jenkins was only building the image, not running it. Added docker run
in pipeline.
β Port conflict:
Bind for 0.0.0.0:5000 failed: port is already allocated
β
Found out registry
container was using it. Stopped it:
docker stop registry && docker rm registry
β Final Output
Once fixed, the Jenkins pipeline:
Builds the Docker image
Cleans up old containers
Runs the Flask app
App accessible at:
π http://localhost:5000
π Key Takeaways
β
Docker alone isn't enough β CI/CD automation is where DevOps shines
β
Always check running containers with docker ps
β
Port conflicts are real and sneaky β clean up before re-running
β
Jenkins won't run your app unless you explicitly add that step!
β
Working from scratch gives you production-like debugging experience
π§ Lesson You Learned (and Should Highlight in Blog/LinkedIn)
βEven if CI/CD automation works at script level, we must validate app health post-deployment β especially in local setups where ports and services can clash.β
Subscribe to my newsletter
Read articles from Harshitha G M directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Harshitha G M
Harshitha G M
I am a DevOps enthusiast with hands-on experience in CI/CD pipelines, containerization, and automation using tools like Jenkins, Docker, Kubernetes, and Ansible. I work on building and deploying Flask-based applications and configuring end-to-end DevOps workflows from scratch. Passionate about cloud-native technologies and automation, I focus on optimizing deployment processes and ensuring smooth software delivery.