How to Use Jenkins Freestyle Project for Docker Applications | Day 23 of 90 Days of DevOps
Hello, everyone!
I am back with another blog post on my DevOps learning journey with 90DaysOfDevops. Today, I will show you how to use Jenkins freestyle project for building and running Docker applications.
What is CI/CD?
CI/CD stands for continuous integration and continuous delivery or deployment. It is a set of practices that help software development teams deliver code changes more frequently and reliably. CI/CD is part of DevOps, which helps shorten the software development lifecycle.
The main concepts attributed to CI/CD are:
- Continuous integration: The practice of automating the integration of code changes from multiple developers into a single codebase. It involves building, testing, and merging the code regularly using tools like Jenkins.
- Continuous delivery: The practice of automating the delivery of code changes to a staging or production environment where they can be tested further and verified by the stakeholders. It involves deploying the code using tools like Docker.
- Continuous deployment: The practice of automating the release of code changes to the end-users without human intervention. It involves deploying the code using tools like Kubernetes.
What is a Build Job?
A build job in Jenkins is a configuration for automating a specific task or step in the application-building process. These tasks include gathering dependencies, compiling, archiving, transforming, testing, and deploying the code.
Jenkins supports different types of build jobs, such as:
- Freestyle project: A flexible and easy-to-use type of build job that allows you to configure any build job using a graphical user interface. You can add multiple build steps and post-build actions using various plugins.
- Pipeline project: A powerful and expressive type of build job that allows you to define your build job using a script or a graphical editor. You can create complex workflows and stages using Groovy syntax or declarative syntax.
- Multi-configuration project: A type of build job that allows you to run your build job on multiple platforms or environments using different parameters or configurations. You can use matrices or axes to define the combinations of parameters or configurations.
- Folder: A type of build job that allows you to organize your build jobs into folders or subfolders. You can use folders to group related build jobs or create nested views.
- Multibranch pipeline: A type of build job that allows you to create pipelines for different branches of your source code repository. You can use Jenkinsfiles to define your pipelines in each branch.
- Organization folder: A type of build job that allows you to create pipelines for multiple repositories in an organization or a team. You can use Jenkinsfiles to define your pipelines in each repository.
What is a Freestyle Project?
A freestyle project in Jenkins is a type of build job that allows you to automate simple jobs, such as running tests, creating and packaging applications, producing reports, or executing commands.
A freestyle project consists of:
- General settings: The settings that define the name, description, parameters, options, and triggers of your project.
- Source code management: The settings that define how to access your source code from a version control system such as Git, SVN, CVS, etc.
- Build environment: The settings that define how to set up your build environment such as environment variables, credentials, tools, etc.
- Build steps: The steps that define what commands or actions to execute during your build such as shell scripts, batch commands, Ant tasks, Maven goals, etc.
- Post-build actions: The actions that define what to do after your build such as archiving artifacts, publishing reports, sending notifications, etc.
How to Create and Run a Freestyle Project for Docker Applications?
In this section, I will show you how to create and run two freestyle projects for building and running Docker applications.
Create a Freestyle Project for Building and Running a Single Container
In this task, I will create a freestyle project that builds an image for a simple web application using Docker and runs a container using the image.
The web application is written in Python using Flask framework and displays “Hello World” on the homepage.
The Dockerfile for the web application is:
# Use python:3-alpine as base image
FROM python:3-alpine
# Set the working directory to /app
WORKDIR /app
# Copy the requirements.txt file to /app
COPY requirements.txt /app
# Install the dependencies
RUN pip install -r requirements.txt
# Copy the app.py file to /app
COPY app.py /app
# Expose port 5000
EXPOSE 5000
# Run the app.py file as the entrypoint
ENTRYPOINT ["python", "app.py"]
To create a freestyle project for this task, follow these steps:
- Go to your Jenkins dashboard and click on New Item.
- Enter a name for your project (e.g., Flask App) and select Freestyle project. Then click OK.
- On the configuration page, you can add some description for your project if you want.
- Under Source Code Management, select Git and enter the repository URL: https://github.com/ajitfawade/hello-flask. You can leave the other fields as default.
- Under Build Triggers, you can choose when you want your project to run automatically. For example, you can select Build periodically and enter a cron expression (e.g.,
* * * * *
) to run your project every minute. For this task, we will leave this section blank and run our project manually. - Under Build, click on Add build step and select Execute shell (or Execute Windows batch command if you are using Windows). This will allow you to run any shell or batch command as part of your project.
- In the text area that appears, enter the command
docker build -t hello_flask .
to build the image for the web application using Docker. The-t
flag specifies the name of the image (hello_flask) and the.
specifies the current directory as the build context. - Add another build step by clicking on Add build step and select Execute shell (or Execute Windows batch command if you are using Windows).
- In the text area that appears, enter the command
docker run -d -p 5000:5000 --name flask-app flask-app
to run a container using the image created in step 7. The-d
flag runs the container in detached mode, the-p
flag maps port 5000 of the container to port 5000 of the host, and the--name
flag specifies the name of the container (flask-app).
Click Save to save your project.
Now, go back to your Jenkins dashboard and click on your project name (e.g., Flask App). Then click on Build Now to run your project.
You will see a new build number appear under Build History with a blue ball indicating that the build is in progress. You can click on it to see the details of the build.
Click on Console Output to see the logs of the build. You should see something like this:
Started by user Ajit Fawade
Running as SYSTEM
Building on the built-in node in workspace /var/lib/jenkins/workspace/Flask-App
The recommended git tool is: NONE
No credentials specified
> git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/Flask-App/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/ajitfawade/hello-flask # timeout=10
Fetching upstream changes from https://github.com/ajitfawade/hello-flask
> git --version # timeout=10
> git --version # 'git version 2.37.2'
> git fetch --tags --force --progress -- https://github.com/ajitfawade/hello-flask +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision ce08b6602fb4a7b1b759ecb2403b1a65ac4695df (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f ce08b6602fb4a7b1b759ecb2403b1a65ac4695df # timeout=10
Commit message: "initial commit"
> git rev-list --no-walk ce08b6602fb4a7b1b759ecb2403b1a65ac4695df # timeout=10
[Flask-App] $ /bin/sh -xe /tmp/jenkins11088220101026471931.sh
+ echo Build Started...
Build Started...
+ docker build -t hello_flask .
Sending build context to Docker daemon 62.46kB
Step 1/7 : FROM python:3-alpine
---> cecbd2a9585a
Step 2/7 : WORKDIR /app
---> Using cache
---> 10845ae000e5
Step 3/7 : COPY requirements.txt /app
---> ab42686079e7
Step 4/7 : RUN pip install -r requirements.txt
---> Running in f37353f9052e
Collecting Flask==2.1.1 (from -r requirements.txt (line 1))
Downloading Flask-2.1.1-py3-none-any.whl (95 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 95.2/95.2 kB 1.0 MB/s eta 0:00:00
Collecting Werkzeug>=2.0 (from Flask==2.1.1->-r requirements.txt (line 1))
Downloading werkzeug-2.3.7-py3-none-any.whl (242 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 242.2/242.2 kB 8.6 MB/s eta 0:00:00
Collecting Jinja2>=3.0 (from Flask==2.1.1->-r requirements.txt (line 1))
Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 2.0 MB/s eta 0:00:00
Collecting itsdangerous>=2.0 (from Flask==2.1.1->-r requirements.txt (line 1))
Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting click>=8.0 (from Flask==2.1.1->-r requirements.txt (line 1))
Downloading click-8.1.7-py3-none-any.whl (97 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB 5.5 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0 (from Jinja2>=3.0->Flask==2.1.1->-r requirements.txt (line 1))
Downloading MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl (33 kB)
Installing collected packages: MarkupSafe, itsdangerous, click, Werkzeug, Jinja2, Flask
Successfully installed Flask-2.1.1 Jinja2-3.1.2 MarkupSafe-2.1.3 Werkzeug-2.3.7 click-8.1.7 itsdangerous-2.1.2
[91mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[0m[91m
[notice] A new release of pip is available: 23.1.2 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
[0mRemoving intermediate container f37353f9052e
---> bc907efb1c48
Step 5/7 : COPY app.py /app
---> 209fa5b29c7c
Step 6/7 : EXPOSE 5000
---> Running in ee9b711979e3
Removing intermediate container ee9b711979e3
---> fedc26e26f75
Step 7/7 : ENTRYPOINT ["python", "app.py"]
---> Running in 6ebfa7384c18
Removing intermediate container 6ebfa7384c18
---> 13ca4741eebe
Successfully built 13ca4741eebe
Successfully tagged hello_flask:latest
+ echo Code Deployed...
Code Deployed...
+ docker run -d -p 5000:5000 --name flask-app hello_flask
597e68b6906525eadbe971abd2a9d9b8204b63e058022a09a4698ce2422617b8
Finished: SUCCESS
You can see that the image and the container are created successfully and the container ID is printed at the end.
You can also verify that the container is running by going to your browser and typing http://localhost:5000
. You should see “Hello World” on the homepage.
Create a Freestyle Project for Building and Running Multiple Containers
In this task, I will create a freestyle project that builds and runs multiple containers using a docker-compose file.
The docker-compose file defines two services: a web application and a database. The web application is the same as in task-01, but it connects to the database using SQLAlchemy. The database is a PostgreSQL server that stores some data for the web application.
The source code for the web application and the database is available on GitHub: https://github.com/LondheShubham153/two-tier-flask-app
The docker-compose file for the application and the database is:
version: '3'
services:
backend:
build:
context: .
ports:
- "5000:5000"
environment:
MYSQL_HOST: mysql
MYSQL_USER: your_username
MYSQL_PASSWORD: your_password
MYSQL_DB: your_database
depends_on:
- mysql
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: your_root_password
MYSQL_DATABASE: your_database
MYSQL_USER: your_username
MYSQL_PASSWORD: your_password
volumes:
- ./message.sql:/docker-entrypoint-initdb.d/message.sql # Mount sql script into container's /docker-entrypoint-initdb.d directory
- mysql-data:/var/lib/mysql # Mount the volume for MySQL data storage
volumes:
mysql-data:
To create a freestyle project for this task, follow these steps:
- Go to your Jenkins dashboard and click on New Item.
- Enter a name for your project (e.g., Flask DB App) and select Freestyle project. Then click OK.
- On the configuration page, you can add some description for your project if you want.
- Under Source Code Management, select Git and enter the repository URL: https://github.com/LondheShubham153/two-tier-flask-app. You can leave the other fields as default.
- Under Build Triggers, you can choose when you want your project to run automatically. For example, you can select Build periodically and enter a cron expression (e.g.,
* * * * *
) to run your project every minute. For this task, we will leave this section blank and run our project manually. - Under Build, click on Add build step and select Execute shell (or Execute Windows batch command if you are using Windows). This will allow you to run any shell or batch command as part of your project.
- In the text area that appears, enter the command
docker-compose up -d
to start the multiple containers defined in the docker-compose file using Docker. The-d
flag runs the containers in detached mode.
8. Under Post-build Actions, click on Add post-build action and select Execute shell (or Execute Windows batch command if you are using Windows). This will allow you to run any shell or batch command after your build is finished.
9. In the text area that appears, enter the command docker-compose down
to stop and remove the containers defined in the docker-compose file using Docker.
10. Click Save to save your project.
Now, go back to your Jenkins dashboard and click on your project name (e.g., Flask DB App). Then click on Build Now to run your project.
You will see a new build number appear under Build History with a blue ball indicating that the build is in progress. You can click on it to see the details of the build.
Click on Console Output to see the logs of the build. You should see something like this:
Started by user Ajit Fawade
Running as SYSTEM
Building on the built-in node in workspace /var/lib/jenkins/workspace/Two tier app
The recommended git tool is: NONE
No credentials specified
> git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/Two tier app/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/LondheShubham153/two-tier-flask-app # timeout=10
Fetching upstream changes from https://github.com/LondheShubham153/two-tier-flask-app
> git --version # timeout=10
> git --version # 'git version 2.37.2'
> git fetch --tags --force --progress -- https://github.com/LondheShubham153/two-tier-flask-app +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision e85f7753ad50b1c2e2a044ad598fc39d01379ec4 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f e85f7753ad50b1c2e2a044ad598fc39d01379ec4 # timeout=10
Commit message: "Merge pull request #2 from AnupamRoy2191/master"
> git rev-list --no-walk e85f7753ad50b1c2e2a044ad598fc39d01379ec4 # timeout=10
[Two tier app] $ /bin/sh -xe /tmp/jenkins16701918866267187274.sh
+ echo Build Started...
Build Started...
+ docker-compose up -d
mysql Pulling
70e9ff4420fb Pulling fs layer
7ca4383b183f Pulling fs layer
3e282e7651b1 Pulling fs layer
1ffa0e0ca707 Pulling fs layer
6eb790cf6382 Pulling fs layer
b4b277ff2929 Pulling fs layer
692fe4469429 Pulling fs layer
c0d447d97bbd Pulling fs layer
99ee594517ba Pulling fs layer
a9ae52de4d77 Pulling fs layer
66cc05a182b5 Pulling fs layer
6eb790cf6382 Waiting
b4b277ff2929 Waiting
692fe4469429 Waiting
c0d447d97bbd Waiting
99ee594517ba Waiting
a9ae52de4d77 Waiting
66cc05a182b5 Waiting
1ffa0e0ca707 Waiting
7ca4383b183f Downloading [=========================================> ] 720B/872B
7ca4383b183f Download complete
3e282e7651b1 Downloading [> ] 10.3kB/983.7kB
3e282e7651b1 Downloading [===> ] 64.81kB/983.7kB
70e9ff4420fb Downloading [> ] 506.2kB/50.48MB
3e282e7651b1 Downloading [==========> ] 200.6kB/983.7kB
70e9ff4420fb Downloading [=> ] 1.026MB/50.48MB
3e282e7651b1 Downloading [==================> ] 359.7kB/983.7kB
70e9ff4420fb Downloading [=> ] 1.534MB/50.48MB
3e282e7651b1 Downloading [==================================> ] 671kB/983.7kB
3e282e7651b1 Verifying Checksum
3e282e7651b1 Download complete
70e9ff4420fb Downloading [==> ] 2.575MB/50.48MB
70e9ff4420fb Downloading [===> ] 3.603MB/50.48MB
70e9ff4420fb Downloading [====> ] 4.635MB/50.48MB
70e9ff4420fb Downloading [=====> ] 5.655MB/50.48MB
70e9ff4420fb Downloading [======> ] 6.675MB/50.48MB
70e9ff4420fb Downloading [=======> ] 7.711MB/50.48MB
70e9ff4420fb Downloading [========> ] 8.739MB/50.48MB
70e9ff4420fb Downloading [=========> ] 9.775MB/50.48MB
1ffa0e0ca707 Downloading [> ] 47.1kB/4.601MB
70e9ff4420fb Downloading [==========> ] 10.79MB/50.48MB
1ffa0e0ca707 Downloading [=> ] 143kB/4.601MB
70e9ff4420fb Downloading [===========> ] 11.82MB/50.48MB
1ffa0e0ca707 Downloading [===> ] 294.1kB/4.601MB
70e9ff4420fb Downloading [============> ] 12.83MB/50.48MB
1ffa0e0ca707 Downloading [=====> ] 539.9kB/4.601MB
6eb790cf6382 Downloading [=============> ] 720B/2.658kB
6eb790cf6382 Downloading [==================================================>] 2.658kB/2.658kB
6eb790cf6382 Download complete
1ffa0e0ca707 Downloading [=======> ] 735.6kB/4.601MB
70e9ff4420fb Downloading [=============> ] 13.86MB/50.48MB
1ffa0e0ca707 Downloading [===========> ] 1.03MB/4.601MB
70e9ff4420fb Downloading [==============> ] 14.88MB/50.48MB
1ffa0e0ca707 Downloading [==============> ] 1.325MB/4.601MB
70e9ff4420fb Downloading [===============> ] 15.9MB/50.48MB
1ffa0e0ca707 Downloading [================> ] 1.522MB/4.601MB
1ffa0e0ca707 Downloading [===================> ] 1.768MB/4.601MB
70e9ff4420fb Downloading [================> ] 16.94MB/50.48MB
1ffa0e0ca707 Downloading [======================> ] 2.063MB/4.601MB
70e9ff4420fb Downloading [=================> ] 17.95MB/50.48MB
1ffa0e0ca707 Downloading [========================> ] 2.272MB/4.601MB
1ffa0e0ca707 Downloading [==========================> ] 2.468MB/4.601MB
70e9ff4420fb Downloading [==================> ] 18.97MB/50.48MB
1ffa0e0ca707 Downloading [============================> ] 2.665MB/4.601MB
70e9ff4420fb Downloading [===================> ] 19.99MB/50.48MB
1ffa0e0ca707 Downloading [================================> ] 3.009MB/4.601MB
70e9ff4420fb Downloading [====================> ] 21.01MB/50.48MB
1ffa0e0ca707 Downloading [==================================> ] 3.205MB/4.601MB
1ffa0e0ca707 Downloading [======================================> ] 3.5MB/4.601MB
70e9ff4420fb Downloading [=====================> ] 22.03MB/50.48MB
1ffa0e0ca707 Downloading [=========================================> ] 3.795MB/4.601MB
70e9ff4420fb Downloading [======================> ] 23.05MB/50.48MB
1ffa0e0ca707 Downloading [===========================================> ] 4.041MB/4.601MB
b4b277ff2929 Downloading [==================================================>] 333B/333B
b4b277ff2929 Verifying Checksum
1ffa0e0ca707 Downloading [==============================================> ] 4.287MB/4.601MB
70e9ff4420fb Downloading [=======================> ] 24.07MB/50.48MB
1ffa0e0ca707 Downloading [=================================================> ] 4.582MB/4.601MB
1ffa0e0ca707 Verifying Checksum
1ffa0e0ca707 Download complete
70e9ff4420fb Downloading [========================> ] 25.09MB/50.48MB
70e9ff4420fb Downloading [=========================> ] 26.11MB/50.48MB
70e9ff4420fb Downloading [==========================> ] 27.14MB/50.48MB
70e9ff4420fb Downloading [===========================> ] 27.65MB/50.48MB
70e9ff4420fb Downloading [============================> ] 28.67MB/50.48MB
70e9ff4420fb Downloading [=============================> ] 29.69MB/50.48MB
70e9ff4420fb Downloading [==============================> ] 30.71MB/50.48MB
70e9ff4420fb Downloading [===============================> ] 31.74MB/50.48MB
c0d447d97bbd Downloading [==================================================>] 317B/317B
c0d447d97bbd Download complete
70e9ff4420fb Downloading [================================> ] 32.76MB/50.48MB
692fe4469429 Downloading [> ] 260.4kB/25.54MB
70e9ff4420fb Downloading [=================================> ] 33.79MB/50.48MB
692fe4469429 Downloading [=> ] 522.6kB/25.54MB
70e9ff4420fb Downloading [==================================> ] 34.81MB/50.48MB
692fe4469429 Downloading [=> ] 780.6kB/25.54MB
70e9ff4420fb Downloading [===================================> ] 35.83MB/50.48MB
692fe4469429 Downloading [==> ] 1.043MB/25.54MB
70e9ff4420fb Downloading [====================================> ] 36.86MB/50.48MB
70e9ff4420fb Downloading [=====================================> ] 37.88MB/50.48MB
692fe4469429 Downloading [===> ] 1.571MB/25.54MB
70e9ff4420fb Downloading [======================================> ] 38.4MB/50.48MB
70e9ff4420fb Downloading [=======================================> ] 39.43MB/50.48MB
692fe4469429 Downloading [===> ] 1.829MB/25.54MB
70e9ff4420fb Downloading [========================================> ] 40.46MB/50.48MB
692fe4469429 Downloading [====> ] 2.091MB/25.54MB
692fe4469429 Downloading [====> ] 2.353MB/25.54MB
70e9ff4420fb Downloading [=========================================> ] 41.48MB/50.48MB
692fe4469429 Downloading [=====> ] 2.616MB/25.54MB
70e9ff4420fb Downloading [==========================================> ] 42.51MB/50.48MB
692fe4469429 Downloading [=====> ] 2.878MB/25.54MB
70e9ff4420fb Downloading [===========================================> ] 43.55MB/50.48MB
692fe4469429 Downloading [======> ] 3.14MB/25.54MB
70e9ff4420fb Downloading [============================================> ] 44.57MB/50.48MB
692fe4469429 Downloading [======> ] 3.406MB/25.54MB
692fe4469429 Downloading [=======> ] 3.668MB/25.54MB
70e9ff4420fb Downloading [=============================================> ] 45.59MB/50.48MB
692fe4469429 Downloading [=======> ] 3.93MB/25.54MB
99ee594517ba Downloading [> ] 539.9kB/88.62MB
70e9ff4420fb Downloading [==============================================> ] 46.6MB/50.48MB
692fe4469429 Downloading [========> ] 4.193MB/25.54MB
99ee594517ba Downloading [> ] 1.08MB/88.62MB
692fe4469429 Downloading [========> ] 4.455MB/25.54MB
70e9ff4420fb Downloading [===============================================> ] 47.63MB/50.48MB
99ee594517ba Downloading [> ] 1.616MB/88.62MB
692fe4469429 Downloading [=========> ] 4.713MB/25.54MB
70e9ff4420fb Downloading [===============================================> ] 48.13MB/50.48MB
99ee594517ba Downloading [=> ] 2.153MB/88.62MB
70e9ff4420fb Downloading [================================================> ] 48.64MB/50.48MB
692fe4469429 Downloading [=========> ] 4.975MB/25.54MB
70e9ff4420fb Downloading [================================================> ] 49.15MB/50.48MB
99ee594517ba Downloading [=> ] 3.222MB/88.62MB
99ee594517ba Downloading [==> ] 3.754MB/88.62MB
692fe4469429 Downloading [==========> ] 5.237MB/25.54MB
70e9ff4420fb Downloading [=================================================> ] 49.66MB/50.48MB
99ee594517ba Downloading [==> ] 4.295MB/88.62MB
70e9ff4420fb Downloading [=================================================> ] 50.17MB/50.48MB
99ee594517ba Downloading [==> ] 4.836MB/88.62MB
692fe4469429 Downloading [==========> ] 5.499MB/25.54MB
99ee594517ba Downloading [===> ] 5.909MB/88.62MB
70e9ff4420fb Verifying Checksum
70e9ff4420fb Download complete
692fe4469429 Downloading [===========> ] 5.757MB/25.54MB
70e9ff4420fb Extracting [> ] 524.3kB/50.48MB
99ee594517ba Downloading [===> ] 6.99MB/88.62MB
70e9ff4420fb Extracting [==> ] 2.621MB/50.48MB
99ee594517ba Downloading [====> ] 8.067MB/88.62MB
692fe4469429 Downloading [===========> ] 6.019MB/25.54MB
70e9ff4420fb Extracting [=====> ] 5.243MB/50.48MB
99ee594517ba Downloading [=====> ] 9.141MB/88.62MB
70e9ff4420fb Extracting [=======> ] 7.34MB/50.48MB
99ee594517ba Downloading [=====> ] 10.21MB/88.62MB
70e9ff4420fb Extracting [=========> ] 9.437MB/50.48MB
99ee594517ba Downloading [======> ] 11.28MB/88.62MB
692fe4469429 Downloading [============> ] 6.282MB/25.54MB
70e9ff4420fb Extracting [==========> ] 11.01MB/50.48MB
99ee594517ba Downloading [======> ] 12.36MB/88.62MB
70e9ff4420fb Extracting [===========> ] 12.06MB/50.48MB
99ee594517ba Downloading [=======> ] 13.43MB/88.62MB
692fe4469429 Downloading [============> ] 6.544MB/25.54MB
70e9ff4420fb Extracting [=============> ] 13.63MB/50.48MB
99ee594517ba Downloading [========> ] 14.5MB/88.62MB
70e9ff4420fb Extracting [================> ] 16.25MB/50.48MB
99ee594517ba Downloading [========> ] 15.58MB/88.62MB
70e9ff4420fb Extracting [===================> ] 19.4MB/50.48MB
99ee594517ba Downloading [=========> ] 16.65MB/88.62MB
692fe4469429 Downloading [=============> ] 6.806MB/25.54MB
70e9ff4420fb Extracting [======================> ] 22.54MB/50.48MB
99ee594517ba Downloading [==========> ] 17.73MB/88.62MB
70e9ff4420fb Extracting [=======================> ] 24.12MB/50.48MB
692fe4469429 Downloading [=============> ] 7.068MB/25.54MB
99ee594517ba Downloading [==========> ] 18.8MB/88.62MB
70e9ff4420fb Extracting [=========================> ] 25.69MB/50.48MB
99ee594517ba Downloading [===========> ] 19.86MB/88.62MB
70e9ff4420fb Extracting [============================> ] 28.31MB/50.48MB
99ee594517ba Downloading [===========> ] 20.93MB/88.62MB
70e9ff4420fb Extracting [==============================> ] 30.93MB/50.48MB
692fe4469429 Downloading [==============> ] 7.33MB/25.54MB
99ee594517ba Downloading [============> ] 22.01MB/88.62MB
70e9ff4420fb Extracting [===============================> ] 31.98MB/50.48MB
99ee594517ba Downloading [=============> ] 23.08MB/88.62MB
70e9ff4420fb Extracting [================================> ] 32.51MB/50.48MB
99ee594517ba Downloading [=============> ] 24.14MB/88.62MB
70e9ff4420fb Extracting [================================> ] 33.03MB/50.48MB
692fe4469429 Downloading [==============> ] 7.592MB/25.54MB
99ee594517ba Downloading [==============> ] 25.23MB/88.62MB
70e9ff4420fb Extracting [==================================> ] 34.6MB/50.48MB
99ee594517ba Downloading [==============> ] 26.31MB/88.62MB
70e9ff4420fb Extracting [===================================> ] 36.18MB/50.48MB
99ee594517ba Downloading [===============> ] 27.38MB/88.62MB
692fe4469429 Downloading [===============> ] 7.854MB/25.54MB
70e9ff4420fb Extracting [=====================================> ] 37.75MB/50.48MB
99ee594517ba Downloading [================> ] 28.47MB/88.62MB
70e9ff4420fb Extracting [=======================================> ] 40.37MB/50.48MB
99ee594517ba Downloading [================> ] 29.53MB/88.62MB
70e9ff4420fb Extracting [==========================================> ] 42.99MB/50.48MB
99ee594517ba Downloading [=================> ] 30.6MB/88.62MB
692fe4469429 Downloading [===============> ] 8.117MB/25.54MB
70e9ff4420fb Extracting [============================================> ] 44.56MB/50.48MB
99ee594517ba Downloading [=================> ] 31.66MB/88.62MB
99ee594517ba Downloading [==================> ] 32.73MB/88.62MB
70e9ff4420fb Extracting [=============================================> ] 46.14MB/50.48MB
99ee594517ba Downloading [===================> ] 33.81MB/88.62MB
99ee594517ba Downloading [===================> ] 34.89MB/88.62MB
70e9ff4420fb Extracting [==============================================> ] 47.19MB/50.48MB
a9ae52de4d77 Downloading [======> ] 719B/5.395kB
a9ae52de4d77 Downloading [==================================================>] 5.395kB/5.395kB
a9ae52de4d77 Verifying Checksum
a9ae52de4d77 Download complete
99ee594517ba Downloading [====================> ] 35.97MB/88.62MB
692fe4469429 Downloading [================> ] 8.379MB/25.54MB
99ee594517ba Downloading [====================> ] 37.03MB/88.62MB
70e9ff4420fb Extracting [================================================> ] 48.76MB/50.48MB
99ee594517ba Downloading [=====================> ] 38.09MB/88.62MB
70e9ff4420fb Extracting [==================================================>] 50.48MB/50.48MB
692fe4469429 Downloading [================> ] 8.649MB/25.54MB
99ee594517ba Downloading [======================> ] 39.16MB/88.62MB
692fe4469429 Downloading [=================> ] 8.911MB/25.54MB
70e9ff4420fb Pull complete
7ca4383b183f Extracting [==================================================>] 872B/872B
7ca4383b183f Extracting [==================================================>] 872B/872B
7ca4383b183f Pull complete
3e282e7651b1 Extracting [=> ] 32.77kB/983.7kB
99ee594517ba Downloading [=======================> ] 42.37MB/88.62MB
3e282e7651b1 Extracting [==================================================>] 983.7kB/983.7kB
692fe4469429 Downloading [=================> ] 9.169MB/25.54MB
3e282e7651b1 Pull complete
1ffa0e0ca707 Extracting [> ] 65.54kB/4.601MB
99ee594517ba Downloading [========================> ] 43.44MB/88.62MB
1ffa0e0ca707 Extracting [=======> ] 720.9kB/4.601MB
99ee594517ba Downloading [=========================> ] 44.51MB/88.62MB
1ffa0e0ca707 Extracting [=============================> ] 2.753MB/4.601MB
692fe4469429 Downloading [==================> ] 9.431MB/25.54MB
1ffa0e0ca707 Extracting [==================================================>] 4.601MB/4.601MB
99ee594517ba Downloading [==========================> ] 46.13MB/88.62MB
1ffa0e0ca707 Pull complete
6eb790cf6382 Extracting [==================================================>] 2.658kB/2.658kB
6eb790cf6382 Extracting [==================================================>] 2.658kB/2.658kB
99ee594517ba Downloading [==========================> ] 47.21MB/88.62MB
692fe4469429 Downloading [==================> ] 9.694MB/25.54MB
6eb790cf6382 Pull complete
b4b277ff2929 Extracting [==================================================>] 333B/333B
b4b277ff2929 Extracting [==================================================>] 333B/333B
99ee594517ba Downloading [===========================> ] 48.27MB/88.62MB
b4b277ff2929 Pull complete
99ee594517ba Downloading [===========================> ] 49.36MB/88.62MB
692fe4469429 Downloading [===================> ] 9.956MB/25.54MB
99ee594517ba Downloading [============================> ] 50.43MB/88.62MB
99ee594517ba Downloading [=============================> ] 51.51MB/88.62MB
99ee594517ba Downloading [=============================> ] 52.59MB/88.62MB
692fe4469429 Downloading [===================> ] 10.22MB/25.54MB
99ee594517ba Downloading [==============================> ] 53.66MB/88.62MB
99ee594517ba Downloading [==============================> ] 54.75MB/88.62MB
692fe4469429 Downloading [====================> ] 10.48MB/25.54MB
99ee594517ba Downloading [===============================> ] 55.83MB/88.62MB
99ee594517ba Downloading [================================> ] 56.9MB/88.62MB
99ee594517ba Downloading [================================> ] 57.98MB/88.62MB
692fe4469429 Downloading [=====================> ] 10.74MB/25.54MB
66cc05a182b5 Downloading [==================================================>] 121B/121B
66cc05a182b5 Verifying Checksum
99ee594517ba Downloading [=================================> ] 59.06MB/88.62MB
99ee594517ba Downloading [=================================> ] 60.14MB/88.62MB
692fe4469429 Downloading [=====================> ] 11MB/25.54MB
99ee594517ba Downloading [==================================> ] 61.2MB/88.62MB
99ee594517ba Downloading [===================================> ] 62.27MB/88.62MB
99ee594517ba Downloading [===================================> ] 63.35MB/88.62MB
99ee594517ba Downloading [====================================> ] 64.43MB/88.62MB
99ee594517ba Downloading [====================================> ] 65.51MB/88.62MB
99ee594517ba Downloading [=====================================> ] 66.58MB/88.62MB
692fe4469429 Downloading [======================> ] 11.27MB/25.54MB
99ee594517ba Downloading [======================================> ] 67.66MB/88.62MB
99ee594517ba Downloading [======================================> ] 68.2MB/88.62MB
692fe4469429 Downloading [======================> ] 11.54MB/25.54MB
99ee594517ba Downloading [=======================================> ] 69.29MB/88.62MB
99ee594517ba Downloading [=======================================> ] 69.83MB/88.62MB
692fe4469429 Downloading [=======================> ] 11.8MB/25.54MB
99ee594517ba Downloading [========================================> ] 70.91MB/88.62MB
99ee594517ba Downloading [========================================> ] 71.99MB/88.62MB
99ee594517ba Downloading [=========================================> ] 73.07MB/88.62MB
692fe4469429 Downloading [=======================> ] 12.06MB/25.54MB
99ee594517ba Downloading [=========================================> ] 74.14MB/88.62MB
692fe4469429 Downloading [========================> ] 12.32MB/25.54MB
99ee594517ba Downloading [==========================================> ] 75.73MB/88.62MB
99ee594517ba Downloading [===========================================> ] 76.8MB/88.62MB
692fe4469429 Downloading [========================> ] 12.59MB/25.54MB
99ee594517ba Downloading [===========================================> ] 77.87MB/88.62MB
99ee594517ba Downloading [============================================> ] 78.95MB/88.62MB
692fe4469429 Downloading [=========================> ] 12.85MB/25.54MB
99ee594517ba Downloading [=============================================> ] 80.03MB/88.62MB
99ee594517ba Downloading [=============================================> ] 81.1MB/88.62MB
692fe4469429 Downloading [=========================> ] 13.11MB/25.54MB
99ee594517ba Downloading [==============================================> ] 82.18MB/88.62MB
99ee594517ba Downloading [==============================================> ] 83.25MB/88.62MB
692fe4469429 Downloading [==========================> ] 13.37MB/25.54MB
99ee594517ba Downloading [===============================================> ] 84.32MB/88.62MB
99ee594517ba Downloading [================================================> ] 85.4MB/88.62MB
692fe4469429 Downloading [==========================> ] 13.63MB/25.54MB
99ee594517ba Downloading [================================================> ] 86.49MB/88.62MB
99ee594517ba Downloading [=================================================> ] 87.56MB/88.62MB
692fe4469429 Downloading [===========================> ] 13.89MB/25.54MB
99ee594517ba Downloading [=================================================> ] 88.62MB/88.62MB
99ee594517ba Verifying Checksum
99ee594517ba Download complete
692fe4469429 Downloading [============================> ] 14.42MB/25.54MB
692fe4469429 Downloading [============================> ] 14.68MB/25.54MB
692fe4469429 Downloading [=============================> ] 14.94MB/25.54MB
692fe4469429 Downloading [=============================> ] 15.2MB/25.54MB
692fe4469429 Downloading [==============================> ] 15.46MB/25.54MB
692fe4469429 Downloading [===============================> ] 15.99MB/25.54MB
692fe4469429 Downloading [================================> ] 16.51MB/25.54MB
692fe4469429 Downloading [=================================> ] 17.04MB/25.54MB
692fe4469429 Downloading [==================================> ] 17.56MB/25.54MB
692fe4469429 Downloading [===================================> ] 18.09MB/25.54MB
692fe4469429 Downloading [====================================> ] 18.62MB/25.54MB
692fe4469429 Downloading [=====================================> ] 19.41MB/25.54MB
692fe4469429 Downloading [=======================================> ] 20.2MB/25.54MB
692fe4469429 Downloading [=========================================> ] 20.98MB/25.54MB
692fe4469429 Downloading [==========================================> ] 21.77MB/25.54MB
692fe4469429 Downloading [============================================> ] 22.55MB/25.54MB
692fe4469429 Downloading [=============================================> ] 23.35MB/25.54MB
692fe4469429 Downloading [===============================================> ] 24.4MB/25.54MB
692fe4469429 Downloading [=================================================> ] 25.44MB/25.54MB
692fe4469429 Verifying Checksum
692fe4469429 Download complete
692fe4469429 Extracting [> ] 262.1kB/25.54MB
692fe4469429 Extracting [==> ] 1.311MB/25.54MB
692fe4469429 Extracting [======> ] 3.146MB/25.54MB
692fe4469429 Extracting [===========> ] 5.767MB/25.54MB
692fe4469429 Extracting [================> ] 8.389MB/25.54MB
692fe4469429 Extracting [=====================> ] 11.01MB/25.54MB
692fe4469429 Extracting [===========================> ] 13.89MB/25.54MB
692fe4469429 Extracting [==============================> ] 15.73MB/25.54MB
692fe4469429 Extracting [=====================================> ] 19.14MB/25.54MB
692fe4469429 Extracting [==========================================> ] 21.76MB/25.54MB
692fe4469429 Extracting [==============================================> ] 23.59MB/25.54MB
692fe4469429 Extracting [==================================================>] 25.54MB/25.54MB
692fe4469429 Pull complete
c0d447d97bbd Extracting [==================================================>] 317B/317B
c0d447d97bbd Extracting [==================================================>] 317B/317B
c0d447d97bbd Pull complete
99ee594517ba Extracting [> ] 557.1kB/88.62MB
99ee594517ba Extracting [=> ] 2.228MB/88.62MB
99ee594517ba Extracting [==> ] 4.456MB/88.62MB
99ee594517ba Extracting [====> ] 7.242MB/88.62MB
99ee594517ba Extracting [=====> ] 10.03MB/88.62MB
99ee594517ba Extracting [=======> ] 13.37MB/88.62MB
99ee594517ba Extracting [=========> ] 16.71MB/88.62MB
99ee594517ba Extracting [===========> ] 20.05MB/88.62MB
99ee594517ba Extracting [============> ] 22.84MB/88.62MB
99ee594517ba Extracting [===============> ] 27.3MB/88.62MB
99ee594517ba Extracting [================> ] 29.52MB/88.62MB
99ee594517ba Extracting [==================> ] 32.31MB/88.62MB
99ee594517ba Extracting [===================> ] 33.98MB/88.62MB
99ee594517ba Extracting [====================> ] 36.21MB/88.62MB
99ee594517ba Extracting [======================> ] 39.55MB/88.62MB
99ee594517ba Extracting [=======================> ] 41.78MB/88.62MB
99ee594517ba Extracting [========================> ] 44.01MB/88.62MB
99ee594517ba Extracting [=========================> ] 45.68MB/88.62MB
99ee594517ba Extracting [==========================> ] 46.24MB/88.62MB
99ee594517ba Extracting [==========================> ] 46.79MB/88.62MB
99ee594517ba Extracting [==========================> ] 47.35MB/88.62MB
99ee594517ba Extracting [===========================> ] 47.91MB/88.62MB
99ee594517ba Extracting [===========================> ] 48.46MB/88.62MB
99ee594517ba Extracting [===========================> ] 49.02MB/88.62MB
99ee594517ba Extracting [===========================> ] 49.58MB/88.62MB
99ee594517ba Extracting [============================> ] 50.14MB/88.62MB
99ee594517ba Extracting [============================> ] 50.69MB/88.62MB
99ee594517ba Extracting [============================> ] 51.25MB/88.62MB
99ee594517ba Extracting [=============================> ] 51.81MB/88.62MB
99ee594517ba Extracting [=============================> ] 52.36MB/88.62MB
99ee594517ba Extracting [=============================> ] 52.92MB/88.62MB
99ee594517ba Extracting [==============================> ] 53.48MB/88.62MB
99ee594517ba Extracting [==============================> ] 54.03MB/88.62MB
99ee594517ba Extracting [===============================> ] 55.15MB/88.62MB
99ee594517ba Extracting [================================> ] 56.82MB/88.62MB
99ee594517ba Extracting [================================> ] 57.38MB/88.62MB
99ee594517ba Extracting [=================================> ] 59.05MB/88.62MB
99ee594517ba Extracting [==================================> ] 61.83MB/88.62MB
99ee594517ba Extracting [====================================> ] 65.18MB/88.62MB
99ee594517ba Extracting [======================================> ] 67.4MB/88.62MB
99ee594517ba Extracting [=======================================> ] 70.19MB/88.62MB
99ee594517ba Extracting [========================================> ] 72.42MB/88.62MB
99ee594517ba Extracting [===========================================> ] 76.32MB/88.62MB
99ee594517ba Extracting [============================================> ] 78.54MB/88.62MB
99ee594517ba Extracting [=============================================> ] 80.77MB/88.62MB
99ee594517ba Extracting [==============================================> ] 82.44MB/88.62MB
99ee594517ba Extracting [===============================================> ] 84.67MB/88.62MB
99ee594517ba Extracting [================================================> ] 86.34MB/88.62MB
99ee594517ba Extracting [==================================================>] 88.62MB/88.62MB
99ee594517ba Pull complete
a9ae52de4d77 Extracting [==================================================>] 5.395kB/5.395kB
a9ae52de4d77 Extracting [==================================================>] 5.395kB/5.395kB
a9ae52de4d77 Pull complete
66cc05a182b5 Extracting [==================================================>] 121B/121B
66cc05a182b5 Extracting [==================================================>] 121B/121B
66cc05a182b5 Pull complete
mysql Pulled
#0 building with "default" instance using docker driver
#1 [backend internal] load build definition from Dockerfile
#1 transferring dockerfile: 32B done
#1 DONE 0.0s
#2 [backend internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.6s
#3 [backend internal] load metadata for docker.io/library/python:3.9-slim
#3 DONE 1.0s
#4 [backend 1/7] FROM docker.io/library/python:3.9-slim@sha256:42a5da33675ec5a692e8cdbb09ffa4e39588c10dd9a96235e543c498484ee18e
#4 DONE 0.0s
#5 [backend internal] load build context
#5 transferring context: 4.96kB 0.0s done
#5 DONE 0.5s
#6 [backend 2/7] WORKDIR /app
#6 CACHED
#7 [backend 3/7] RUN apt-get update && apt-get upgrade -y && apt-get install -y gcc default-libmysqlclient-dev pkg-config && rm -rf /var/lib/apt/lists/*
#7 CACHED
#8 [backend 4/7] COPY requirements.txt .
#8 CACHED
#9 [backend 5/7] RUN pip install mysqlclient
#9 CACHED
#10 [backend 6/7] RUN pip install --no-cache-dir -r requirements.txt
#10 CACHED
#11 [backend 7/7] COPY . .
#11 CACHED
#12 [backend] exporting to image
#12 exporting layers done
#12 writing image sha256:ea53947f9ffaf4236f7d81a189d317db7fe6bdea285cc1b508158a431b5428e2 0.0s done
#12 naming to docker.io/library/twotierapp-backend 0.0s done
#12 DONE 0.8s
Container twotierapp-mysql-1 Creating
Container twotierapp-mysql-1 Created
Container twotierapp-backend-1 Creating
Container twotierapp-backend-1 Created
Container twotierapp-mysql-1 Starting
Container twotierapp-mysql-1 Started
Container twotierapp-backend-1 Starting
Container twotierapp-backend-1 Started
Finished: SUCCESS
You can see that the containers are created, started, stopped, and removed successfully.
You can also verify that the web application is running by going to your browser and typing http://localhost:5000
. You should see “Hello World from Flask and PostgreSQL” on the homepage.
I hope this blog post helps you understand how to use Jenkins freestyle project for building and running Docker applications. In the next blog post, I will show you how to use Jenkins pipeline project for creating more complex workflows and stages.
If you have any questions or feedback, please feel free to contact me on:
- GitHub: https://github.com/ajitfawade
- LinkedIn: https://www.linkedin.com/in/ajitfawade/
Thank you for reading! 😊