MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

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

Install Atlassian Jira with Docker: Quick Start, Persistent Volumes, and Deployment Checks

This guide shows how to run Jira in Docker using the original one-line command, then improve it with persistent storage and repeatable deployment steps. It also includes a workflow diagram, command examples, and practical validation checks.

Read More

Docker commands Guide – docker volume with examples

Here’s a complete tutorial on docker volume, covering what it does, examples, and use cases. What is docker volume? docker volume is a Docker command used to…

Read More

Docker Tutorials: Remove all Docker Containers, all Images, all Volumes, and all Networks

How to stop all Docker Containers To delete all containers including its volumes use How to remove all stopped Docker Containers How to delete all Docker Images…

Read More

Docker Interview Questions and Answer Part – 26

What Docker Client command can be used to convert a Dockerfile into an Image? docker createimage docker buildimage docker build (Ans) docker create Which of the following…

Read More

Docker Interview Questions and Answer Part – 10

What is a dangling volume? The default volume for the container file system that’s unpacked from the image A volume that’s removed from a running container A…

Read More

Debug for Docker Container

To debug a Docker container, check its state and logs first, then its network configuration, then test connectivity from another container on the same network. This page…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
1 month ago

Running Jenkins in Docker makes setup easier and helps keep the environment separate from the host system. One important step is to use a persistent volume so jobs, plugins, and settings survive container restarts. It is also wise to pin the Jenkins image version instead of relying on a changing latest tag. Secure the admin account and limit access to the web interface. These steps make a test setup more reliable and easier to maintain.

1
0
Would love your thoughts, please comment.x
()
x