Installing Jenkins with Docker on AWS Lightsail: A Guide
Written on
Chapter 1: Introduction to Jenkins and Docker
In this guide, we will explore the process of setting up a Jenkins server as a Docker container on an AWS Lightsail instance. Jenkins is a widely-used open-source automation server that facilitates Continuous Integration and Continuous Delivery (CI/CD) tasks. By leveraging Jenkins, you can address various deployment challenges effectively. This tool has gained immense popularity among DevOps professionals.
To get started, we will focus on installing Jenkins via Docker on AWS Lightsail and later discuss how to configure a DevOps pipeline using Jenkins alongside GitHub.
Prerequisites
- An AWS Lightsail server (or any cloud server of your choice)
- Docker installed on your server
Begin by purchasing a cloud server. For demonstration purposes, we will utilize AWS Lightsail. If you don't have Docker installed, you can follow the provided link to get it set up.
Getting the Jenkins Docker Image
To proceed with the installation, you will need the Jenkins Docker image. This image is available on Docker Hub.
Installing Jenkins Using Docker
Now that you have the Jenkins Docker image, you can install it using the Docker run command. Here’s an example of the command you might use:
docker run -d -p host_port:container_port image_name
Run the following command on your server to download the Jenkins image from Docker Hub and set it up as a container:
docker run -d -p 8090:8080 -v jenkins_home:/var/jenkins_home --name jenkins_server jenkins/jenkins:lts-jdk11
In this command, 8090 is the host port, which you can modify according to your preferences.
Retrieving Jenkins Password from Docker Logs
To access your Jenkins server, you will require the default password. You can find this password in the logs of your Jenkins container. Use the command below to get a list of your running Docker containers:
docker ps
Identify the Jenkins Docker container ID from the list, and then retrieve the logs with this command:
docker logs container_id
For example:
docker logs 46ccf42bc48e
The logs will include the password needed to log into Jenkins, as illustrated in the sample logs screenshot.
Allowing Port Access in Lightsail
By default, only port 8080 is open on AWS Lightsail servers. Since the Jenkins container is operating on port 8090, you'll need to enable this port in your AWS Lightsail settings. Navigate to the Network tab to find the option for enabling ports. The process may vary for other cloud service providers, so be sure to check their documentation.
Completing the Jenkins Installation
You can access the Jenkins container using the following URL format:
When you enter this URL in your browser, it will prompt you for the Jenkins default password. Paste the password you copied earlier and click the "Continue" button.
On the next screen, you will be prompted to select the plugins you wish to install. For simplicity, we recommend choosing the suggested plugins, though this may take a bit of time.
After the plugins have been installed, you will create an admin user with a password of your choice. Once this is done, you will be presented with the Jenkins URL. Click on the "Save and Finish" buttons to finalize your setup.
Finally, click on the "Start Using Jenkins" button to launch your Jenkins server.
Summary
Docker simplifies the packaging of applications, allowing for seamless transitions between different platforms without configuration headaches. With Docker, you can easily migrate your applications from one operating system to another with minimal effort. Jenkins has become a go-to tool for DevOps developers, and with the growing trend of containerized applications, understanding how to install Jenkins using Docker is essential.
Stay tuned for future articles where we will delve into configuring a DevOps pipeline using Jenkins and GitHub.
This video covers the process of setting up Jenkins on AWS Lightsail using Docker and building a .NET Core application.
In this video, learn how to install Jenkins and Ansible on EC2, and deploy a Java application on Tomcat within Docker containers.