Delivery Workflows
Running Jenkins in Docker with Persistent Data
Quickly launch a test-friendly Jenkins instance in Docker, maintain configuration between restarts, and safely trial new features.
Sometimes you need a clean Jenkins instance to test plugins, major upgrades, or new pipeline ideas without touching an existing CI system. Running Jenkins in Docker is an easy way to create that environment quickly, and adding persistent storage means the instance can survive restarts while you iterate.
Quick Ephemeral Setup
For a fast disposable instance:
docker run -p 8080:8080 jenkins/jenkins:lts-jdk17
That is enough for short-lived testing, but any configuration changes will disappear when the container is removed.
Persistent Jenkins with Docker Compose
To keep configuration, jobs, and installed plugins between restarts, mount a persistent volume for jenkins_home:
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins:lts-jdk17
ports:
- '8080:8080'
- '50000:50000'
volumes:
- 'jenkins_home:/var/jenkins_home'
volumes:
jenkins_home:
Then start it with:
docker compose up -d
That gives you a persistent Jenkins instance that can be stopped and started without losing local configuration.
Extending Your Jenkins Image
Sometimes the test instance also needs extra tooling such as the AWS CLI or OpenTofu. Instead of installing those tools manually inside the running container, you can build a custom image on top of the Jenkins base image.
For example:
FROM jenkins/jenkins:lts-jdk17
USER root
RUN apt-get update && \
apt-get install -y curl unzip python3 python3-pip && \
pip3 install awscli && \
rm -rf /var/lib/apt/lists/*
USER jenkins
Build it locally:
docker build -t jenkins-local .
Then update your Compose file to use jenkins-local as the image.
Additional Considerations
- Security: If the instance is more than a local test, secure it properly before exposing it anywhere.
- Networking: Compose networks make it easy to connect Jenkins to other local services.
- Version control: Keep the Compose file and Dockerfile in Git so you can reproduce and evolve the environment cleanly.
Conclusion
Running Jenkins in Docker is a practical way to test changes without disturbing a shared CI environment. Adding persistent storage makes the instance much more useful for repeated trials, and a custom image lets you shape it around the tools your pipelines actually need.