Learn to configure a Jenkins pipeline with Docker for continuous integration and deployment of applications.
In this lesson, you’ll learn how to configure a Jenkins pipeline integrated with Docker, enabling continuous integration and deployment for your applications. Before you start, ensure Docker is installed on your Jenkins server so that it can access the Docker CLI. For installation instructions, please refer to the Docker documentation page.
Make sure Docker is installed and properly configured on your Jenkins server before proceeding.
The first step is to configure Jenkins with your Docker Hub credentials. Create credentials within Jenkins using the “Username with password” type. Enter your Docker Hub account name as the username and your Docker Hub password as the password. In this example, the credentials are named “Docker creds”.
Next, navigate back to the Jenkins dashboard and create a new pipeline named “Docker pipeline”. In the pipeline configuration screen, make the following selections:
Enable “GitHub hook trigger for GITScm polling”.
Choose “Pipeline script from SCM”.
Select Git as your SCM and provide the URL of your repository.
Set the branch to “main” and keep the default path to your Jenkinsfile.
Tagging your Docker images with the Git commit hash creates a direct link between the image and a specific commit in your repository. This makes it easy to track deployments back to the source code changes. For example, checking the commit history on GitHub can help you verify that the correct changes have been deployed.
If you view a commit diff, you might see something like this:
After making changes (for example, updating the version to “version four”), commit and push the modifications. Jenkins will trigger another build, and your updated Docker image—now tagged with the new commit hash—will be pushed to Docker Hub.
Finally, you can verify the pushed Docker image on Docker Hub. The Docker Hub interface displays details such as the manifest digest, OS/architecture, compressed size, and image layers.
This completes the process of integrating Docker into your Jenkins CI/CD pipeline, enabling streamlined testing, building, and deployment of your applications.