Difficulty: Advanced
Estimated Time: 15-20 minutes

In this scenario you'll learn how to configure Jenkins to build Docker Images based on a Dockerfile. The scenario is designed to demostrate how you can use Docker within a CI/CD pipeline, using Images as a build artefact that can be promoted to different environments and finally production.

The environment pre-configured and running Jenkins build server for you to experiment and learn how it works. The steps guide you to installing the plugin, creating a build and viewing the results.

This scenario took a new Jenkins build and configured it to build Docker Images. We then look an example HTTP server and created a build for it.

Learn how to launch a Private Docker Registry with our scenario.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Building Docker Images using Jenkins v2.46.2

Step 1 of 6

Launch Jenkins

This is a fork of https://github.com/oveits/jenkins-scenarios of Ben Hall, upgraded from Jenkins 1.651.1 to 2.46.2.

We will prepare an environment with a Jenkins server running as a Docker Container.

First we start the container in detached mode with a tail to a log file we will create and use later:

docker run -d -u root --rm --name jenkins \ -p 8080:8080 -p 50000:50000 \ --entrypoint bash \ jenkins:2.46.2-alpine \ -c "tail -F /jenkins.log"

With the next command, we clone a Jenkins Home directory into the container, before we start the Jenkins application. The Jenkins Home directory has been prepared to allow us using Jenkins without any login:

docker exec -d jenkins \ bash -c 'git clone https://github.com/oveits/jenkins_home_alpine \ && export JENKINS_HOME=$(pwd)/jenkins_home_alpine \ && java -jar /usr/share/jenkins/jenkins.war 2>&1 1>/jenkins.log &'

After a minute or so, we should see that the jenkins.war is started:

docker exec jenkins ps -ef

Load Dashboard

You can load the Jenkins' dashboard via the following URL https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/ or by clicking the dashboard tab on the right.

In the next steps, you'll use the dashboard to configure the plugins and start building Docker Images.