Basic Docker Jenkins Installation
(this post is part of the material I cover in my devops course)
There are many ways to install and run Jenkins.
It can be installed on many platforms, in many ways
as explained in the jenkins documentation.
I'll present here the docker way, because it is an easy one.
Install Docker
If docker is not installed yet, install it as described
here.
Installation instruction can sometimes be misleading, and I learned that what I really need is the docker engine (not the Docker desktop).
The system I use is Ubuntu.
Create a docker network
Create a docker bridge network by using this command:
1docker network create jenkins
You can verify this by using:
1docker network ls
Run the jenkins container
Use the following (somewhat long) command:
1docker run \
2 --name jenkins \
3 --restart=on-failure \
4 --detach \
5 --network jenkins \
6 --env DOCKER_HOST=tcp://docker:2376 \
7 --env DOCKER_CERT_PATH=/certs/client \
8 --env DOCKER_TLS_VERIFY=1 \
9 --publish 8080:8080 \
10 --volume jenkins-data:/var/jenkins_home \
11 --volume jenkins-docker-certs:/certs/client:ro \
12 jenkins/jenkins
This command does the following:
- It runs a container from jenkins/jenkins image
- It calls it: jenkins
- It is detached (so not using the current tty for i/o)
- It uses the jenkins network we have just created
- Creates (or mounts) 2 volumes to be used by the container
- publish port number 8080 to the external OS
Post Run
- Browse jenkins using localhost:8080
- Unlock jenkins by finding the admin password that jenkins write to the stdio.
- First exec into the jenkins container:
1docker exec -it jenkins /bin/bash
- Then view the initial password:
1cat /var/jenkins_home/secrets/initialAdminPassword
- now, paste this into your browser
- Install suggested plugins:
Browse to localhost:8080 and Jenkins will suggest plugins to be installed for you. click on install suggested plugins and wait until all plugins are installed. - Add admin user:
Add the details of an admin user (it is not recommended to use the admin that was already created) Configure the URL: You can leave that as http://localhost:8080/ but make sure that the Jenkins server can access itself using this url - You'll get Jenkins is ready message, so click Start using Jenkins