Master Jenkins From Beginner to Enterprise

Clear, interactive, and structured Jenkins lessons designed to take you from beginner to enterprise level.

Jenkins with Docker

Learn how to containerize your automation infrastructure by deploying Jenkins inside Docker, managing configuration data via volumes, and executing pipeline builds in isolated containers.

What is Jenkins with Docker?

Running Jenkins with Docker involves spinning up the Jenkins controller inside an isolated software container rather than installing dependencies directly onto a host OS. This guarantees that your CI/CD server remains fully decoupled from host environments, enabling rapid updates, consistent states, and seamless scaling.

Critical Guardrail: Containers are inherently ephemeral. To avoid losing your build jobs, configurations, and plugin data when a container stops, you must attach an external **Docker Volume** to persist the /var/jenkins_home directory.

Key Concepts

1. Official Container Registry

Always pull from the official jenkins/jenkins:lts image on Docker Hub. Avoid deprecated community tags like jenkins or jenkinsci.

2. Port Mapping Strategy

Map host ports to the container: port 8080 provides browser access to the web GUI, while port 50000 coordinates communication for inbound build agents.

3. Data Persistence Volume

Using the -v jenkins_home:/var/jenkins_home flag redirects Jenkins internal configuration mutations cleanly onto the host filesystem storage.

4. Docker-in-Docker (DinD)

Allows the Jenkins controller to spin up isolated container worker slots dynamically to isolate and run specialized project compile steps.

Docker Setup and Startup Scripts

Use this CLI initialization layout step to download the official image, map network ports, name the container daemon block, and safely link a data-backed storage configuration path:

# 1. Pull down the highly stable, officially supported Long-Term Support image tag
docker pull jenkins/jenkins:lts












# 2. Run the container instance detached in the background with port and volume mapping
docker run -d \
  --name my-jenkins-server \
  -p 8080:8080 \
  -p 50000:50000 \
  -v jenkins_data:/var/jenkins_home \
  --restart=on-failure \
  jenkins/jenkins:lts

# 3. Stream and inspect the running initialization logs to retrieve your initial setup password
docker logs my-jenkins-server

Practice Exercise

  1. Ensure the Docker engine is running on your computer terminal.
  2. Execute the docker run orchestration script provided in the example workspace above.
  3. Open your web browser and navigate to http://localhost:8080 to view the unlock validation view page.
  4. Fetch your unique setup token without logging into the file system directly by typing:
    docker exec my-jenkins-server cat /var/jenkins_home/secrets/initialAdminPassword.

Summary

You have completed the Jenkins with Docker lesson. You are now prepared to launch sandboxed automation controllers, control baseline configuration instances via volume binding hooks, and handle container runtime flags.