docker-compose Jenkins with persistent data

  • Docker compose yaml

This guide will focus on the local environment for now, but should be easy to adapt to higher env’s. The focus of the guide is how to run Jenkins image, add changes to it, and load then on next start.

Create a following file on your local machine and go to that location in the terminal.

docker-compose.yaml file:

version: '2'
    image: 'jenkins/jenkins:lts'
      kompose.service.type: nodeport
      - '80:8080'
      - '443:8443'
      - '50000:50000'
      - 'jenkins_data:/jenkins_config'
    driver: local

Under services: we define which image is used. I used the one from Docker hub located Under tags you choose your own version but I prefer running on LTS at least while testing locally.

Kompose.service.type is used so it is also kompose compatible.

The volume is perhaps the most relevant in this case since we define the name & location of the volume hard as jenkins_data:/jenkins_config as well as defining type of driver used for volume.


Cool, we have a nice yaml setup. Now in the terminal we execute
docker compose up
to fire up with the correct image etc. Now the actual jenkins should be available.

To check for your password that you will need for the first time check first which container id is associated with your newly ran container.

You can do that with:

docker ps

To actually check the logs use:

docker logs CONTAINER_ID

In the output of the above command you should see message like


Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

After going to the local Jenkins URL, setting up plugins etc. you can use
docker-compose stop to persist data on the data volume.
And upon next start simply use docker-compose start for it.

This is hopefully an easy and straightforward setup for anyone wanting to focus a bit more on CI/CD specific case.

By |June 6th, 2018|Categories: ALL, How to, The Code|

About the Author:

Senior lead developer currently working in Java, architecture design, mix of tech from Front-end in JS and templating to chef,rundeck etc. For fun and challenge I am writing different blog posts from stories to poems, programming tutorials and many more. Currently working on my Masters degree on a part-time basis.