Installing Jenkins on Docker
1. Introduction
Jenkins is an open-source automation server that facilitates continuous integration and continuous delivery (CI/CD). By running Jenkins in a Docker container, you can easily manage dependencies and isolate your Jenkins environment from your host system.
2. Prerequisites
- Docker installed on your server or local machine.
- Basic knowledge of command-line interface (CLI).
- Access to the internet (to pull Docker images).
3. Installation Process
3.1 Pull the Jenkins Docker Image
Use the following command to pull the official Jenkins image from Docker Hub:
docker pull jenkins/jenkins:lts
3.2 Run the Jenkins Container
To run Jenkins, execute this command:
docker run -d -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
This command runs Jenkins in detached mode (-d), mapping port 8080 on your host to port 8080 on the container and port 50000 for Jenkins agents.
3.3 Verify the Installation
To verify that Jenkins is running, open your web browser and navigate to http://localhost:8080. You should see the Jenkins setup wizard.
4. Initial Configuration
During the first launch, Jenkins will ask for an unlock key. To retrieve this key, run the following command:
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
Copy the output from the command and paste it into the unlock screen in your browser.
Next, follow the on-screen instructions to complete the setup, including:
- Selecting the installation type (recommended, custom, etc.).
- Installing suggested plugins or selecting specific plugins to install.
- Creating an admin user and configuring Jenkins settings.
5. FAQ
What is Docker?
Docker is a platform that enables developers to automate the deployment of applications inside lightweight containers.
How do I update Jenkins running on Docker?
You can stop the current Jenkins container and pull the latest image using docker pull jenkins/jenkins:lts
, then run a new container.
Can I persist Jenkins data?
Yes, you can persist data by mounting a volume. For example: docker run -d -v jenkins_home:/var/jenkins_home -p 8080:8080 jenkins/jenkins:lts