In this article, I will go over how you can start Jenkins up on a remote server using the official image from Docker.
In this tutorial, for our server, I will use DigitalOcean.
I do want to preface this by saying, running a remote server on DigitalOcean is not free. However, it is relatively cheap to start one up.
Let's get started!
Creating/Configuring The Server
1) Create an account with Digital Ocean.
- Type "digitalocean.com" in your browser
- Click the "Sign Up" button on the top right of the website.
- You can either create an account with your email, Github, or Google.
- After you create an account, you will need to verify that it's you.
2) Next, you want to create a Digital Ocean (Droplet)
3) After creating a Digital Ocean Droplet, you want to configure some settings. Lets break it down!
First, we will choose an image based on our current distribution. Currently, my machine is Linux Mint, so it is Ubuntu-based. Therefore, I will select "Ubuntu"
Second, we will select our plan. I will go with the cheapest and select "Basic".
Third, in our CPU Options, we will select "Regular Intel with SSD" and select the $20/month plan.
Fourth, select the region closest to you.
Fifth, we will select our authentication option as SSH.If you don't have an SSH already configured, let's configure it!
Click "New SSH Key". A prompt will open up. On the right pane, you will see a command of "ssh-keygen" Follow the instructions given.
Finally, click "Create Droplet"
3) Let's rename our droplet to something meaningful. I will be renaming mine to jenkins-tutorial-server.
4) Copy the IPV4 address because we will need it when configuring our firewall rules.
5) Click on networking link and scroll down to Firewall and click "Edit"
6) Next, we click the button that says "Create Firewall".
7) We can name our firewall whatever we want. I will be naming mine "jenkins-tutorial-firewall".
8) Next, we will paste our IPV4 address in the source of PORT 22.
9) We also want to add a custom port of 8080 to our Inbound Rules
10) Finally, add the droplet we created to the Firewalls Rules at the bottom and click "Create"
Accessing The Remote Server Via Terminal
Now, that we have created and configured our server on DigitalOcean, it is time to access it.
1) Open the terminal and ssh into your server by using the IPv4 address..
2) Once you hit enter, you will be given a prompt of
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type in "Yes" and hit enter again.
Now, you are inside your remote server.
3) Run apt update
4) After that is complete, we need to install Docker by running the command run apt install docker.io
5) Then, to install Jenkins, we need to run the command docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
With p 8080:8080
we are binding the port that we specified in our Firewall of our server. This will allow us to access the UI of Jenkins.
With -p 50000:50000
, we are specifying the port that the controller and agent nodes speak to each other on. Jenkins runs on a Controller-Agent architecture (that's a lesson for another day).
With -d
, we are running it in detached mode. This means that it will be running in the background.
With v jenkins_home:/var/jenkins_home
we are using Docker Volumes to reference a volume name to bind where the data is being stored to the local machine. This insures that when we stop our container, all the data and configurations we make is not lost.
Finally, with jenkins/jenkins:lts
, we are pulling and executing the official Jenkins latest image.
6) After running this command, you want to type your IPv4 address, add a :
and port 8080
. Once you do, you will be greeting with a Jenkins Page
7) We need the initial password to login. To do this we need to do the following steps:
- In the terminal run
docker ps
. - Copy the Container ID
- Run
docker exec -it <container_image> /bin/bash
- Now, we are inside the docker container that is running Jenkins.
- Run
cat /var/jenkins_home/secrets/initialAdminPassword
- Copy the password and paste it into the field of the Sign
In Page.
8) Next, after logging in successfully, we will select Install Suggested Plugins
10) Now, we wait until all the plugins are installed
11) Next, we create our own admin user.
12) Congratulations, you successfully setup Jenkins on your own remote server on DigitalOcean using Docker!!
Now, you can poke around, create jobs, install plugins, etc in Jenkins!