Using Docker and Jenkins for Building and Deploying a ToDo App
👋Hello I am Mohd Saif, passionate technology enthusiast currently pursuing a bachelor of Computer application degree.
🎓Education: I am currently pursuing a bachelor of Computer application degree with the focus on coding at Bareilly University my education journey has equipped me with strong foundation in Computer science and I am eager to apply my knowledge to real word challenges.
💡Passion for technology: I have always been deeply passionate about technology and I am particular drawn to devops with AWS.
🚀Skills: 🔹Linux 🔹Shell scripting 🔹Python 🔹Ansible 🔹Docker 🔹Kubernetes 🔹Jenkins CI/CD 🔹Maven 🔹Git and GitHub
✨Future goals: My goal is to facilitate seamless collaboration between development and operations teams, ensuring faster releases and high-quality software. I am a proactive learner, constantly exploring new DevOps trends and practices
Let's create a DevOps To-Do application project using Docker and Jenkins, incorporating the provided image and emphasizing the use of Jenkins freestyle projects. We will clone the To-Do application code from a GitHub repository.
Project Overview
We'll create a simple To-Do application using Flask (Python), containerize it using Docker, and set up Jenkins to automate the build and deployment process using freestyle projects.
Project Steps
1. Set Up Your Development Environment
Install Docker: Docker Installation Guide
Install Jenkins: Jenkins Installation Guide
2. Create a Simple To-Do Application
Create a simple To-Do application using Flask (Python).
Directory Structure:
to_do_app/
├── app/
│ ├── __init__.py
│ ├── views.py
│ └── models.py
├── requirements.txt
└── Dockerfile
Example Code:
app/__init__.py:from flask import Flask app = Flask(__name__) from app import views if __name__ == '__main__': app.run(debug=True, host='0.0.0.0')app/views.py:from app import app from flask import render_template, request tasks = [] @app.route('/') def index(): return render_template('index.html', tasks=tasks) @app.route('/add', methods=['POST']) def add(): task = request.form.get('task') tasks.append(task) return render_template('index.html', tasks=tasks)requirements.txt:FlaskDockerfile:FROM python:3.8-slim WORKDIR /app COPY requirements.txt requirements.txt RUN pip install -r requirements.txt COPY . . CMD ["python", "app/__init__.py"]

This is my VMware Linux terminal where I used the vi Dockerfile command to create this script, as shown in the image above.
3. Build and Run Docker Container
Build the Docker image:
docker build . -t todo-app
Run the Docker container:
docker run -d -p 8003:8001 760fe61141e4

4. Set Up Jenkins
Install necessary plugins: Docker, Git


Create a new Jenkins Freestyle project
5. Create Jenkins Freestyle Project
Create a New Job:
Open Jenkins and click on "New Item".

Enter a name for your project (e.g.,
To-Do-App) and select "Freestyle project".
Configure the Job:

Build Steps:
- Add a build step "Execute shell" and add the following commands to build and run the Docker container:
#!/bin/bash
sudo sh -c 'cd /root/projects/django-todo && sudo docker build . -t todo-dev'
sudo docker run -d -p 8000:8000 todo-app

6. Build Now and Console Output
Build Now

Console output


7. Run the Jenkins Job
Trigger the Jenkins job manually or wait for the scheduled polling. It will:
Checkout the code from GitHub.
Build the Docker image.
Run the Docker container.
Diagram Representation
Here's how the DevOps flow looks using the provided image:

GitHub: Source code repository where the To-Do application code resides.
Jenkins: Continuous Integration tool that pulls the latest code from GitHub, builds the Docker image, and runs the Docker container.
Docker: Containerization tool that packages the To-Do application into a container and runs it.
Final Notes
Ensure Docker and Jenkins are properly configured to run on your server or local machine.
Use environment variables and secret management for sensitive data.
Customize the To-Do application and testing as needed.
This setup provides a basic framework for integrating Docker and Jenkins (using freestyle projects) into a CI/CD pipeline for a To-Do application. You can expand upon it by adding more stages, tests, and features as needed.

