03 / 06

How to set up and start Jenkins using Docker?

Set up Jenkins using Docker by pulling the official jenkins/jenkins:lts image and running it with the necessary port mappings and volume mounts for persistent data and Docker access

Running Jenkins in a Docker container is the quickest way to get started, as it eliminates manual dependency installations and provides isolation. The official Jenkins image includes everything needed to run Jenkins, and you can customize it by mounting volumes for persistent storage and accessing the Docker daemon from within the container .

Basic Docker Run Command

For Jenkins to build and run Docker containers as part of your CI/CD pipelines, it needs access to the Docker daemon. The cleanest approach is to mount the host's Docker socket into the Jenkins container. This gives Jenkins the ability to execute Docker commands without running Docker-in-Docker .

Run Jenkins with Docker Socket Access

After starting the container, Jenkins generates an initial admin password. You'll need this to unlock Jenkins during first-time setup. Once unlocked, you can install recommended plugins and create your admin user .

Retrieve Initial Admin Password
Step-by-Step Quick Setup
  1. 1

    Pull the image: docker pull jenkins/jenkins:lts

  2. 2

    Run with persistence: Use the -v jenkins_home:/var/jenkins_home flag to ensure your configurations survive container restarts or upgrades

  3. 3

    Map ports: Always map port 8080 for the web UI and optionally port 50000 for agent connections

  4. 4

    Add Docker access: Mount the Docker socket (-v /var/run/docker.sock:/var/run/docker.sock) to enable Jenkins pipelines to build and run containers

  5. 5

    Retrieve the password: Run docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword to get the initial unlock key

For a more manageable setup, especially when you need to add other services like Nginx or databases, use Docker Compose. Create a docker-compose.yml file that defines the Jenkins service with all the necessary volume mounts and port mappings. This is particularly useful for version-controlling your Jenkins configuration and simplifying restarts .

Docker Compose Example

If Jenkins cannot execute Docker commands, verify that the Docker socket is correctly mounted and that permissions are set. For hosts with AppArmor or SELinux restrictions, you may need additional configuration. Also ensure that the Jenkins user inside the container has the necessary permissions—the official image runs as user jenkins (UID 1000), and the mounted socket must be readable by that UID .

Difficulty: 5/10
Topics: Docker containerization, Jenkins configuration, CI/CD pipeline

Scenario Questions

0-2 years experience
  1. 1

    We need a Jenkins server for a small team. How would you use Docker to get Jenkins up and running on a developer's laptop?

  2. 2

    If you run docker run -p 8080:8080 jenkins/jenkins:lts and can't access the UI, what are the common reasons and how would you troubleshoot?

2-5 years experience
  1. 1

    Your team wants Jenkins to pull code from a private GitHub repo, but the Docker container can't authenticate. How would you configure the container to provide the necessary credentials?

  2. 2

    After upgrading the Jenkins Docker image, some of your existing jobs fail because plugins are missing. Walk me through how you'd diagnose and resolve the issue.

5-8 years experience
  1. 1

    We plan to run multiple Jenkins agents as Docker containers behind a reverse proxy for high availability. What architectural considerations and trade‑offs would you evaluate?

  2. 2

    During a heavy load, the Jenkins master container experiences out‑of‑memory kills. How would you redesign the Docker deployment to improve stability and scalability?

8+ years experience
  1. 1

    Our organization is migrating from a legacy on‑prem Jenkins setup to a fully containerized, Kubernetes‑based CI/CD platform. What strategy would you propose to ensure zero‑downtime migration, data integrity, and future maintainability?

  2. 2

    How would you design a shared Docker image strategy for Jenkins master and agents that balances security patches, plugin version consistency, and team autonomy across multiple product lines?

Follow-up Questions

  • What would you add to the Docker run command to enable TLS for the Jenkins UI?
  • How do you decide between using Docker volumes versus host directories for JENKINS_HOME?
  • Can you describe a monitoring approach for the Jenkins container in production?