How to Install Jenkins on Docker: Step-by-Step Guide
To install
Jenkins on Docker, run the command docker run -d -p 8080:8080 -p 50000:50000 --name jenkins jenkins/jenkins:lts. This pulls the official Jenkins image and starts the Jenkins server accessible on port 8080.Syntax
The basic command to install Jenkins on Docker is:
docker run -d -p 8080:8080 -p 50000:50000 --name jenkins jenkins/jenkins:ltsExplanation of each part:
docker run: Starts a new Docker container.-d: Runs the container in detached mode (in the background).-p 8080:8080: Maps port 8080 of the container to port 8080 on your machine (Jenkins web interface).-p 50000:50000: Maps port 50000 for Jenkins agent communication.--name jenkins: Names the container "jenkins" for easy reference.jenkins/jenkins:lts: Uses the official Jenkins image with the latest stable (LTS) version.
bash
docker run -d -p 8080:8080 -p 50000:50000 --name jenkins jenkins/jenkins:lts
Example
This example shows how to pull and run Jenkins in Docker, then access it via a web browser on port 8080.
bash
docker run -d -p 8080:8080 -p 50000:50000 --name jenkins jenkins/jenkins:lts
Output
Unable to find image 'jenkins/jenkins:lts' locally
lts: Pulling from jenkins/jenkins
...
Digest: sha256:...
Status: Downloaded newer image for jenkins/jenkins:lts
<container_id>
Common Pitfalls
Common mistakes when installing Jenkins on Docker include:
- Not mapping ports correctly, so Jenkins is not accessible on your machine.
- Running without persistent storage, causing Jenkins data loss after container removal.
- Not waiting for Jenkins to fully start before accessing the web interface.
To avoid data loss, use a volume to store Jenkins data:
bash
docker run -d -p 8080:8080 -p 50000:50000 --name jenkins -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
Quick Reference
| Command | Description |
|---|---|
| docker run -d -p 8080:8080 -p 50000:50000 --name jenkins jenkins/jenkins:lts | Run Jenkins container with ports mapped |
| docker stop jenkins | Stop the Jenkins container |
| docker start jenkins | Start the Jenkins container again |
| docker rm jenkins | Remove the Jenkins container |
| docker volume create jenkins_home | Create a volume for Jenkins data persistence |
Key Takeaways
Use the official Jenkins Docker image with the 'lts' tag for stability.
Map ports 8080 and 50000 to access Jenkins UI and agents.
Use Docker volumes to keep Jenkins data safe across container restarts.
Run the container in detached mode to keep Jenkins running in the background.
Wait a few minutes after starting before accessing Jenkins on port 8080.