Running Jenkins in Docker is a practical way to launch a CI server quickly while keeping host setup simple. This guide is for DevOps engineers who want a repeatable Jenkins container setup with persistent data, correct port mapping for UI and agents, and day-2 commands for logs and troubleshooting.
Originally published on 2016-03-10; fully revised and updated.

Prerequisites
- A Linux host with Docker installed and running.
- Access to run Docker commands (root or sudo-enabled user).
- A network path to the host on the port you map for Jenkins UI (for example, 8080 or 49001).
- Disk space for Jenkins home data (plugins, jobs, build history, configuration).
Jenkins-on-Docker workflow
flowchart TD
A[Install Docker] --> B[Pull Jenkins image]
B --> C[Prepare persistent data path]
C --> D[Run Jenkins container with ports and volume]
D --> E[Open Jenkins web UI]
E --> F[Get initial admin password]
F --> G[Complete Jenkins setup wizard]
Step 1: Install Docker on the host
The original article used the following package commands:
apt-get install docker
yum install dockerCode language: JavaScript (javascript)
For additional context, the original post also referenced this Docker installation page: http://www.scmgalaxy.com/scm/software-containers/how-to-install-docker-in-linux.html.
Step 2: Pull a Jenkins image
The original command used docker pull jenkins. In current environments, you will commonly see Jenkins images referenced as jenkins/jenkins with a tag.
docker pull jenkins/jenkins:lts
Step 3: Run Jenkins container
Quick start (no persistent host mapping)
docker run --name jenkins -d -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
This is fast for testing, but Jenkins data is not safely mapped to a host directory. If the container is removed, your Jenkins state can be lost.
Persistent setup (recommended)
mkdir -p jenkins_home
chown 1000:1000 jenkins_home
docker run --name jenkins -d -p 8080:8080 -p 50000:50000 -v "$PWD/jenkins_home:/var/jenkins_home" jenkins/jenkins:ltsCode language: JavaScript (javascript)
This follows the original post’s core idea: mount /var/jenkins_home to the host so plugins, jobs, and configuration survive container recreation.
Custom host port and root user variant (only if required)
docker run --name jenkins -d -u root -p 49001:8080 -p 50000:50000 -v "$PWD/jenkins_home:/var/jenkins_home" jenkins/jenkins:ltsCode language: JavaScript (javascript)
This keeps the original example of mapping host port 49001 to container port 8080. Use -u root only when permissions force it; default non-root operation is generally safer.
Container options comparison
| Option | What it controls | Example | When to use |
|---|---|---|---|
-p 8080:8080 | Jenkins web UI port mapping | Host 8080 to container 8080 | Default local access pattern |
-p 49001:8080 | Custom host UI port | Host 49001 to container 8080 | When 8080 is occupied or policy requires another port |
-p 50000:50000 | Inbound agent connection port | Host 50000 to container 50000 | If you use inbound/JNLP-style agents |
-v host_path:/var/jenkins_home | Persistent Jenkins data | -v "$PWD/jenkins_home:/var/jenkins_home" | Recommended for any non-ephemeral usage |
-u root | Container user identity | -u root | Only for permission troubleshooting or specific admin tasks |
Get the initial password and check logs
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
docker logs -f jenkinsCode language: JavaScript (javascript)
The original post showed log access via docker exec name tail -f /var/log/jenkins/jenkins.log. Depending on image layout, that file path may differ; docker logs is usually the most reliable first check.
Access Jenkins in the browser
Open Jenkins at the host and port you mapped, for example:
http://localhost:8080http://localhost:49001(if you mapped49001:8080)http://<host-ip>:49001from another machine
Best practices
- Always persist
/var/jenkins_hometo avoid data loss during container replacement. - Use the least-privilege runtime user whenever possible; avoid permanent
-u rootoperation. - Pin an explicit image tag instead of relying on floating defaults.
- Expose port
50000only if your agent model requires it. - Document your run command (or move to Docker Compose) so rebuilds are repeatable.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals