Installing Jenkins with Docker

Jenkins · Essentials · 10 min

A reproducible local Jenkins is the fastest way to learn pipelines and to test changes before touching a shared server.

Jenkins ships as a WAR file, OS packages and the official Docker image jenkins/jenkins. Use the LTS (long-term support) line for anything serious: it is released every 12 weeks with backported fixes, while weekly releases get new features first. Current Jenkins LTS requires Java 21 or 25 (Java 17 support ended with 2.555.1); the image tag lts-jdk21 bundles Java 21.

Everything Jenkins knows lives in JENKINS_HOME (/var/jenkins_home in the image): jobs, build history, plugins, credentials. Mount it on a named volume so it survives container upgrades, and back it up.

On first start Jenkins writes a one-time admin password to secrets/initialAdminPassword and prints it in the log. Open http://localhost:8080, paste it, choose Install suggested plugins (Git, Pipeline, credentials and more), then create an admin user.

Ports: 8080 for the web UI, 50000 for inbound agents using the TCP protocol (WebSocket agents can use 8080 instead).

Upgrading is mostly replacing the image tag and restarting, then updating plugins in Manage Jenkins, Plugins. Read the LTS upgrade guide first; plugin compatibility is the usual source of trouble.

Example

docker volume create jenkins_home
docker run -d --name jenkins --restart unless-stopped \
  -p 8080:8080 -p 50000:50000 \
  -v jenkins_home:/var/jenkins_home \
  jenkins/jenkins:lts-jdk21

# unlock key for the setup wizard
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
# 3f2a9c... (32 hex characters)

docker logs -f jenkins     # ... Jenkins is fully up and running

Remember

  • Use the LTS line; Jenkins needs Java 21 or 25
  • JENKINS_HOME holds everything: put it on a volume and back it up
  • Unlock with initialAdminPassword, then install suggested plugins

Watch out for

  • Running the container without a volume and losing all jobs on the next upgrade.

Check yourself

  1. Why mount a volume at /var/jenkins_home?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: www.jenkins.io/doc/book/installing/docker/