Following on from the first post in the series, this article will describe how to get Jenkins up and running (as a container) in Docker and the installation of a few plugins that will be useful for the pipeline.
1) Docker installation
Docker provide comprehensive installation instructions on their site. Please follow their instructions and move on to step 2.
Mac instructions
Windows instructions
Linux instructions
2) Jenkins image
Once you have successfully installed, we can also use Docker to quickly (and easily) get a Jenkins instance up and running.
The next stage is to enter the docker console. On Mac this is as easy as launching the Docker QuickStart Terminal application from the launcher. Shown in figure 1 below.
Once in the console, firstly take note of the Virtual Machine IP address.
A message similar to ‘docker is configured to use the default machine with IP 192.168.99.100‘ will be shown.
The remainder of the blog posts will assume that your virtual machine is running on 192.168.99.100.
Now you can pull the Jenkins image:
# docker pull eggsy84/jenkins-maven-git-docker
This will pull down a pre-configured Jenkins image that I have created for this series of posts. The image has Jenkins and Maven both installed. It also installs various Jenkins plugins we shall make use of during the tutorial:
- git
- build pipeline
- Cloudbees docker build and publish
As well as installing Jenkins it will also configure jenkins with the locations of Maven and Docker. For those interested in the Dockerfile it is on my public github account.
It should complete and produce a message similar to:
Digest: sha256:d58a96de4fe25806b561baf3b869e80f0c3cde854aebb090cad8ff56f3114928 Status: Downloaded newer image for eggsy84/jenkins-maven-git-docker:latest
We can then run ‘docker images’ to verify the image is present
# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE eggsy84/jenkins-maven-git-docker latest e27897648e2c 2 hours ago 743.9 MB
3) Starting Jenkins
Once the image download has completed we can start up an instance of Jenkins.
# docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/bin/docker -p 8080:8080 -t eggsy84/jenkins-maven-git-docker:latest
You should see output identifying that Jenkins has started up.
Also note that we have started Jenkins and bounded the docker executable from the host in to the container. This allows us to execute docker commands within the container. Thanks to @jpetazzo for his blog post on that
Open up a browser and navigate to http://192.168.99.100:8080