Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Install Jenkins with Docker: Persistent Setup, Port Mapping, and Logs

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.

Install Jenkins using Docker

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

OptionWhat it controlsExampleWhen to use
-p 8080:8080Jenkins web UI port mappingHost 8080 to container 8080Default local access pattern
-p 49001:8080Custom host UI portHost 49001 to container 8080When 8080 is occupied or policy requires another port
-p 50000:50000Inbound agent connection portHost 50000 to container 50000If you use inbound/JNLP-style agents
-v host_path:/var/jenkins_homePersistent Jenkins data-v "$PWD/jenkins_home:/var/jenkins_home"Recommended for any non-ephemeral usage
-u rootContainer user identity-u rootOnly 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:8080
  • http://localhost:49001 (if you mapped 49001:8080)
  • http://<host-ip>:49001 from another machine

Best practices

  • Always persist /var/jenkins_home to avoid data loss during container replacement.
  • Use the least-privilege runtime user whenever possible; avoid permanent -u root operation.
  • Pin an explicit image tag instead of relying on floating defaults.
  • Expose port 50000 only if your agent model requires it.
  • Document your run command (or move to Docker Compose) so rebuilds are repeatable.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

Automating Jenkins Job Configuration: Job DSL, Multibranch, Job Generator, and JJB

Manually creating many Jenkins jobs is slow and error-prone. This guide compares the main automation options and shows practical jobs-as-code examples for repeatable setup.

Read More

Docker Training Agenda: A Hands-On Learning Path from Containers to Registries and Networking

This revised Docker training agenda turns the original outline into a practical, modern learning path for beginners and early-career DevOps engineers. It maps each module to hands-on outcomes, core commands, and common implementation decisions.

Read More

Jenkins at Scale: Practical References and Admin Cheatsheet

This revised guide upgrades a short 2015 Jenkins link post into an operations-ready reference for teams running Jenkins at scale. It preserves the original links and adds a workflow diagram, comparison table, and practical API/CLI examples.

Read More

Jenkins Backup and Restore Runbook: ThinBackup, Filesystem Archives, and Recovery Steps

A practical Jenkins backup and restore guide for DevOps teams, covering what to back up, strategy trade-offs, and step-by-step command examples. Includes a workflow diagram and a recovery checklist you can operationalize.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x