---
title: "Jumpstart Jenkins in Docker with Docker Compose"
description: "Dive into DevOps with this guide on running Jenkins in Docker containers built using Docker Compose."
canonical: "https://adamtheautomator.com/jenkins-docker/"
---

# Jumpstart Jenkins in Docker with Docker Compose

> Dive into DevOps with this guide on running Jenkins in Docker containers built using Docker Compose.

Source: https://adamtheautomator.com/jenkins-docker/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Jumpstart Jenkins in Docker with Docker Compose](https://adamtheautomator.com/wp-content/uploads/2020/10/How-to-Run-Jenkins-in-Docker-using-Docker-Compose-with-Volumes-2.png)

# Jumpstart Jenkins in Docker with Docker Compose

[![](https://secure.gravatar.com/avatar/9a14f10ff1b1ec7d790d34f5b559e4d3de2d31b172e6ef266dfd8b479174d97b?s=192&d=mm&r=g)June Castillote](https://adamtheautomator.com/author/june/)29 October 20209 min. read

Categories: [DevOps](/category/devops/)

Tags:[Docker](/tag/docker/)[Jenkins](/tag/jenkins/)

Table of Contents

*   [Requirements](#h-requirements)
*   [Running Jenkins in Docker](#h-running-jenkins-in-docker)
*   [Completing the Jenkins in Docker Initial Setup](#h-completing-the-jenkins-initial-setup)
*   [Finding the Jenkins Data in the Container](#h-finding-the-jenkins-data-in-the-container)
*   [Backing Up the Jenkins Data from the Container to the Host](#h-backing-up-the-jenkins-data-from-the-container-to-the-host)
*   [Running Jenkins in Docker with Volume Mount](#h-running-jenkins-in-docker-with-volume-mount)
*   [Finding the Jenkins Data on the Docker Host](#h-finding-the-jenkins-data-on-the-docker-host)
*   [Running Jenkins using Docker Compose with Volumes](#h-running-jenkins-using-docker-compose-with-volumes)
*   [Creating the Docker Compose Files](#h-creating-the-docker-compose-files)
*   [Starting the Jenkins Container using Docker Compose](#h-starting-the-jenkins-container-using-docker-compose)
*   [Summary](#h-summary)
*   [Further Reading](#h-further-reading)

Do you want to run Jenkins in Docker but unsure whether to use volumes or keep the data containerized? If Jenkins is containerized, how do you backup the data? Do you need to back up the entire container? Can information persist outside the container, and how? Using [Docker Compose](https://adamtheautomator.com/docker-compose-tutorial/) with volumes could help you ensure that your Jenkins data be safe even if the Docker container broke.

Apart from backing up data, using Docker volumes allows you to also share Jenkins data between multiple containers.

Keep on reading because, in this article, you will learn how to run Jenkins in Docker and Docker Compose. You’ll learn how to find and potentially backup the Jenkins data inside and outside the Docker container.

## Requirements

There will be a lot of learning examples in this article. If you’d like to follow along, you will need:

*   A computer with _[Docker](https://docs.docker.com/get-docker/)_ and _[Docker Compose](https://docs.docker.com/compose/install/)_ installed. The demos in this article are done in _[Ubuntu Server 20.04](https://adamtheautomator.com/install-ubuntu/)_. You may use Docker on Windows or macOS if you’d prefer.

This article does not cover how to install and setup Docker and Docker Compose. You may refer to the official _[Docker documentation](https://docs.docker.com/)._ The ATA blog also has many _[articles related to Docker](https://adamtheautomator.com/search/docker)_ that you may also want to read.

## Running Jenkins in Docker

To run a Jenkins in Docker, you first need to pull the image from a repository. In this example, the Jenkins image is pulled from _[Docker Hub](https://hub.docker.com/)_. You have the option to download the image first before creating a container. Or you can also run a container and let Docker download the image on the fly.

The command below will run a Jenkins container using the _`docker run`_ command. The `--name [NAME]` option is where you assign a name for the Docker container. If the container name is not specified, Docker assigns a random name to the container.

The `-p [host-port:container-port]` option means to expose the port or ports inside the container to your host computer. In the code below, the ports 8080 and 50000 are exposed to the Docker host using the same port numbers.

Lastly, `jenkins/jenkins:lts` means that the container to run will use the _jenkins:lts_ Docker image from the _[Jenkins repository](https://hub.docker.com/r/jenkins/jenkins)_. You may change the values _name_ and _host port_ numbers if needed, but do not modify the _container_ port numbers.

Please copy the code below and run it in your terminal.

```powershell
docker run --name my-jenkins-1 -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
```

After running the command above, Docker starts to create a new container. Once the Jenkins container is running, take note of the initial admin password displayed on the terminal. The admin password is needed during the Jenkins initial setup.

![The new Jenkins container is running](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-4-3.png)

The new Jenkins container is running

### Completing the Jenkins in Docker Initial Setup

After the Jenkins container entered the running state, you can now access the Jenkins admin page. If you remember from the command you used to create the container, the port number is 8080. So to access the Jenkins instance, navigate to _[HTTP://localhost:8080](HTTP://localhost:8080)_.

As you can see below, the **Unlock Jenkins** page requires you to enter the initial admin password. You should have copied the initial admin password previously. Enter the password in the **Administrator password** box and click on **Continue**.

![Unlocking Jenkins](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-5-3.png)

Unlocking Jenkins

On the **Customize Jenkins** page, you’ll have the option to **Install suggested plugins**. These suggested plugin are the plugins that the Jenkins community typically install. If you have a pre-selected set of plugins to install, choose the **Select plugins to install** option.

For simplicity, the **Install suggested plugins** is the selected option for this example.

![Customizing the Jenkins Plugins' Installation](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-6-3.png)

Customizing the Jenkins Plugins’ Installation

The plugins will be installed, and you can only wait until the installation is finished. As you can see below, there are fourteen (14) suggested plugins being installed. The number of recommended plugins may increase or decrease over time. By the time you installed your Jenkins in Docker, the suggested plugins may already be different.

![Installing the Suggested Plugins](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-7-3.png)

Installing the Suggested Plugins

Immediately after the plugins’ installation finished, you will see the **Create First Admin User** page. This page is where you will create the first Jenkins administrator account. Fill in all the boxes as required and click on **Save and Continue.** Make sure to remember the administrator credential you have just created.

![Creating the first Jenkins administrator account](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-8-3.png)

Creating the first Jenkins administrator account

On the **Instance Configuration** page is where you can change the Jenkins admin page URL. The URL value would typically be the actual URL that will be accessed by the Jenkins users. For this example, leave the default value of [http://localhost:8080](http://localhost:8080) and click on **Save and Finish**.

![Configuring the Jenkins URL](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-9-3.png)

Configuring the Jenkins URL

On the final setup page, you will see the confirmation that the Jenkins in Docker setup is complete. Click on **Start using Jenkins**.

![Completing the Jenkins setup](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-10-3.png)

Completing the Jenkins setup

When you see the **Welcome to Jenkins** page, as shown below, then you’ve completed the Jenkins installation. At this point, you can start configuring Jenkins in Docker and creating new items or projects.

![The Jenkins admin interface](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-11-3.png)

The Jenkins admin interface

### Finding the Jenkins Data in the Container

In the previous section, you created a Docker container to run an instance of Jenkins. Docker containers, just like everything else on a computer, may break. If the container becomes unavailable for some reason, then the Jenkins data is gone too.

To better understand the Jenkins data placement, the code below uses the _`docker exec` command_ to list the contents of the _/var/jenkins\_home_. The Docker container name in this example is _my-jenkins-1._

```powershell
docker exec my-jenkins-1 ls -l /var/jenkins_home
```

You can see below the result of running the command above. The contents of the _/var/jenkins\_home_ directory are listed. The _/var/jenkins\_home_ directory contains the settings, users, plugins, and other critical items.

![Listing the Jenkins configuration directory contents](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-12-2.png)

Listing the Jenkins configuration directory contents

### Backing Up the Jenkins Data from the Container to the Host

At this point, you’ve confirmed that the Jenkins data is found inside the container. You should copy the Jenkins data from the container to the host. And once the Jenkins data is out of the container, you can then take a backup.

It is a good thing that Docker has built-in support for copying files between the Docker container and the Docker host. Using the command `docker cp <container id>:/path/in/container /path/in/host`

The example below uses the `docker cp` command to copy the my-jenkins-1 container’s data to a Docker host location. Note that the container doesn’t even need to be running to execute this command successfully.

```powershell
docker cp my-jenkins-1:/var/jenkins_home ~/jenkins_backup
```

The demo below shows the command above in action. As you can see, the destination directory is automatically created by the command.

![Backing up Jenkins Data](https://adamtheautomator.com/wp-content/uploads/2020/10/docker-cp.gif)

Backing up Jenkins Data

Now that you’ve extracted the Jenkins data from the container, you can perhaps compress and archive the entire folder. You may need to do the same task every time you make changes to Jenkins.

## Running Jenkins in Docker with Volume Mount

To make your Jenkins data persistent and consistent outside of the Docker container, you should use a _[Docker volume](https://docs.docker.com/storage/volumes/)_.

As explained in the previous section, the Jenkins configuration files are located inside the Docker container at _/var/jenkins\_home_. To ensure that the Jenkins files are saved outside of the container, you can use the `-v` option with the `docker run` command.

The code below will create a new Docker container with the name _my-jenkins-2_. The ports 8080 and 50000 will be exposed to the host. Additionally, the _/var/jenkins\_home_ directory inside the Docker container will be mounted as a volume on the host as _jenkins\_home._

```powershell
docker run --name my-jenkins-2 -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
```

After running the command above, the new Docker container should be created and enter the running state. You can confirm that the container is running using the docker ps command.

![Listing all running containers](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-13-2.png)

Listing all running containers

Listing all running containers

### Finding the Jenkins Data on the Docker Host

So, where’s the Jenkins data folder now? Based on the command you used to create the my-jenkins-2 container, the mounted volume is _jenkins\_home_. To know where in the filesystem is the _jenkins\_home_ location can be found, use the `docker volume` command.

The command below will display the details of the _jenkins\_home_ volume on the Docker host.

```powershell
docker volume inspect jenkins_home
```

The screenshot below shows the information about the _jenkins\_home_ volume as the result of running the command above.

![Finding the mounted volume details](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-14-2.png)

Finding the mounted volume details

Now that you know where to find the Jenkins data, you can confirm by exploring the mount point location. In this example, the _jenkins\_home_ volume mount point is in _/var/lib/docker/volumes/jenkins\_home/\_data_.

![Listing the volume contents](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-15-1.png)

Listing the volume contents

Now that the Jenkins data persists outside of the container, you can backup the directory for safekeeping. Also, even if the Jenkins container is deleted, the data will remain on the Docker host.

## Running Jenkins using Docker Compose with Volumes

Another way to run Jenkins is by using the `docker-compose` command. With _Docker Compose_, you can deploy one or more instances of Jenkins, if needed. But before doing so, you need to create a _[Docker Compose file](https://docs.docker.com/compose/compose-file/)_ for each instance.

### Creating the Docker Compose Files

By default, the `docker-compose` command reads the file with the name _docker-compose.yml_ or _docker-compose.yaml_ in the same working directory where you issue the command.

Using your choice of available text editor, open a new blank file. Then, copy the YAML code below, paste it in your editor, and then save the _docker-compose.yml_ file.

```powershell
# docker-compose.yml
version: '3.7'
services:
  jenkins:
    image: jenkins/jenkins:lts
    privileged: true
    user: root
    ports:
      - 8083:8080
      - 50003:50000
    container_name: my-jenkins-3
    volumes:
      - ~/jenkins_data:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
```

This article does not cover the anatomy of a Docker Compose file. You can consult the official _[compose file reference documentation](https://docs.docker.com/compose/compose-file/)_ to understand further what each setting in the compose file means.

But, in this example, you can breakdown the most important settings in both Docker Compose files as listed below.

*   **_image_**: This is the base image to use for creating the Docker container instance.
*   **_ports_**: This is where to define the port mapping between the Docker host and the container.
*   **_volumes_**: These are the volumes mapped between the Docker host and the container.
*   **_container\_name_**: This is the name you want to assign to the container you are creating. In this example, the container name is _my-jenkins-3_.

### Starting the Jenkins Container using Docker Compose

Now that you’ve saved the two Docker Compose files, you can now use them to start the two Jenkins Docker container instances.

To start the _my-jenkins-3_ container, use the command below. Note that the command below assumes that the _docker-compose.yml_ file is in the same directory where you run the command.

```powershell
# Start the my-jenkins-3 container
docker-compose up -d

# Get the initial admin password
docker exec my-jenkins-3 cat /var/jenkins_home/secrets/initialAdminPassword

# Confirm the my-jenkins-3 container is running
docker ps
```

The _my-jenkins-3_ container then starts and enters the running state, as you can see below.

![Starting the my-jenkins-3 Docker container using Docker Compose](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-16.png)

Starting the my-jenkins-3 Docker container using Docker Compose

Navigate the URL [http://localhost:8083](http://localhost:8083) using your browser to access Jenkins and complete the initial setup.

![The my-jenkins-3 Docker container running in port 8083](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-17.png)

The my-jenkins-3 Docker container running in port 8083

After you’ve completed the initial Jenkins setup for the _my-jenkins-3_ container, you can confirm that the ~/jenkins\_data folder is populated with the Jenkins data files.

![The Jenkins configuration files saved in the Docker host location](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-18.png)

The Jenkins configuration files saved in the Docker host location

Since the Jenkins data files persist on the Docker host, even if the _my-jenkins-3_ docker container gets deleted, the configuration shall survive. To further test the persistence of the Jenkins config, stop the _my-jenkins-3_ container using the command below.

```powershell
docker-compose down
```

Note that using the `downer-compose down` command automatically deletes the container itself.

![Stopping a container using Docker Compose](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-19.png)

Stopping a container using Docker Compose

Now, start the _my-jenkins-3_ up again using the command below.

```powershell
docker-compose up -d
```

And when you access the Jenkins web interface, the first page you’ll see is the login page instead of the initial setup page. You’ll find that the same Jenkins configuration is retained, including your login credentials.

![The Jenkins login page](https://adamtheautomator.com/wp-content/uploads/2020/10/Untitled-20.png)

The Jenkins login page

## Summary

In this article, you learned how to run Jenkins using Docker in different ways. You’ve learned how to run Jenkins in Docker with and without a mounted volume. And you’ve learned how to back up the Jenkins data from inside the container to the host.

You also learned how to run a Jenkins instance using Docker Compose with volumes mapped to the Docker host. The Jenkins data files are then saved in the Docker host, making the Jenkins settings persistent and consistent even if the Docker container is deleted.

Using Docker and Docker Compose with volumes gives you the flexibility to back up and ultimately reuse Jenkins’ data. Which method of running Jenkins in Docker do you think you would use more?

## Further Reading

*   _[Deploying your First Container with Docker for Windows](https://adamtheautomator.com/docker-windows/)_
*   _[How to Create (and Manage) Docker Volumes on Windows](https://adamtheautomator.com/create-docker-volume/)_
*   _[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)_

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fjenkins-docker%2F&text=Jumpstart%20Jenkins%20in%20Docker%20with%20Docker%20Compose)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fjenkins-docker%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fjenkins-docker%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/02/featured_image-13.webp)

### [Azure Container Apps: Instant Preview Environments per PR](/build-ephemeral-preview-environments-every-pr/)

Build isolated preview environments for every pull request using Azure Container Apps revision labels and Azure DevOps pipelines with scale-to-zero economics.

![](https://adamtheautomator.com/wp-content/uploads/2025/11/55418e927e511ae263219c072e27d637c2a967a5036de7020b329582db775c26.png)

### [Automating Docker Container Health Checks with Python and Local Notifications](/docker-health-checks-python/)

Docker's built-in health checks are passive—they tell Docker when a container fails, but do they tell you? In this tutorial, we'll build a lightweight Python monitoring system that runs entirely on your infrastructure with zero external dependencies. You'll learn to detect container failures in real-time, send instant alerts, and maintain a complete audit log of every state change.

![](https://adamtheautomator.com/wp-content/uploads/2023/07/gitea-docker.jpg)

### [Gitea Docker: Your Ultimate Self-Hosted Git Solution](/gitea-docker/)

Learn how to install a Gitea Docker instance and self-host Git repositories securely in this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
