How to Install Jenkins with Docker Compose
Docker Compose runs Jenkins in one container with its data on a volume. This guide covers the compose file, first login and the setup traps to avoid.
On this page
Short answer
Installing Jenkins with Docker Compose means running the official Jenkins image as a container and keeping its data in a Docker volume, so the server survives restarts and upgrades. You write a short compose file, start it with one command, then finish setup in the browser with the admin password printed in the container log. The whole job takes under an hour on a fresh server.
What is installing Jenkins with Docker Compose?
Installing Jenkins with Docker Compose is running Jenkins inside a Docker container that Compose starts, stops and updates from a single YAML file. Jenkins is a free automation server that builds, tests and deploys code when a commit lands, and Compose is Docker's tool for describing multi-container setups in one file.
The container holds the Jenkins application, while a named volume holds its home directory: jobs, plugins, build history and settings. That split matters. If you delete the container, the volume keeps your data, so an upgrade is just a new image with the same volume attached.
This is a good fit for small teams and for a first CI server. A single host, one compose file and a volume is enough for dozens of jobs, and you can move the whole setup to another host by copying the volume. For larger fleets, teams usually move to managed DevOps services or a Kubernetes install instead.
What do you need before you start?
You need a Linux host with Docker and the Compose plugin installed, at least 2 GB of RAM and 10 GB of free disk, and port 8080 free for the web interface. Most teams use a small virtual machine or a cloud instance with Ubuntu or Debian, and they open only ports 8080 and 50000.
Check the Docker version first with docker compose version. If that command fails, install the Compose plugin from your distribution's package manager before going further. Also confirm the user running Docker can write to the volume path you plan to use, since Jenkins inside the container runs as its own user.
Keep the host itself patched and put it behind a firewall that only your team can reach. Jenkins has full control over your code and your servers, so an open Jenkins on the public internet is a real risk, not a minor detail.
How do you write the compose file?
The compose file is short. It names one service, pins the Jenkins image to a version, maps the web port and the agent port, and mounts a named volume at the Jenkins home directory. Pin the image tag, such as jenkins/jenkins:2.516-lts, rather than using latest, so upgrades happen when you choose, not by accident.
| Setting | Value | Why it matters |
|---|---|---|
| Image | jenkins/jenkins:2.516-lts | A long-term support release with a fixed version |
| Web port | 8080:8080 | The browser interface your team uses |
| Agent port | 50000:50000 | Build agents connect here |
| Volume | jenkins_home:/var/jenkins_home | Jobs, plugins and history survive restarts |
| Restart | unless-stopped | Jenkins comes back after a host reboot |
| User | 1000:1000 or default | Must match the volume owner on the host |
Save this as docker-compose.yml in its own folder, then run docker compose up -d. The -d flag runs it in the background, and Compose creates the volume on first start. If you compare this with other container tools, the trade-offs are similar to those in the guide to Kubernetes vs Docker.
How do you finish the first setup?
After the container starts, run docker compose logs jenkins and look for the initial admin password, a long string printed near the end of the log. Open http://your-server:8080 in a browser, paste that password, and Jenkins asks whether to install the suggested plugins.
Pick the suggested plugins on a first install. They cover Git, Pipeline, credentials and the tools most jobs need, and you can add more later from the plugin manager. Jenkins then asks you to create an admin user; use a strong password and a real email address, since this account can run any job.
Next, create your first job. A freestyle job that clones a repository and runs a build script is enough to prove the setup works. If the job fails with a permission error, the cause is usually the volume owner: stop the container, fix the ownership with chown, and start it again.
Finally, set the Jenkins URL in the system settings to the address your team actually uses, such as https://ci.example.com. If this stays as localhost, build links in emails and notifications point at the wrong place.
Example (hypothetical): a five-person team sets up Jenkins
Example (hypothetical): a five-person team rents a cloud server with 2 CPU cores and 4 GB of RAM for their first CI server. They write a compose file with the Jenkins long-term support image, a named volume, ports 8080 and 50000, and a restart policy of unless-stopped.
They start it with docker compose up -d, wait about two minutes, then copy the admin password from the log and finish setup in the browser. They install the suggested plugins, create an admin user, and add a freestyle job that clones their repository and runs their test script.
The first build takes 6 minutes, mostly downloading the test dependencies. The second build takes 2 minutes, because the workspace is now cached. Over the next month they add four more jobs, and the volume grows from 1 GB to 3 GB as build history accumulates.
When a new Jenkins version appears, they stop the container, back up the volume, change the image tag in the compose file, and start it again. The whole upgrade takes 10 minutes, and every job and plugin is still there.
What are the common mistakes?
The most common mistakes are running Jenkins as root, using the latest image tag, and losing data because the volume was never created.
- Skipping the volume. Without a named volume, Jenkins data lives inside the container and vanishes when the container is removed.
- Using the latest tag. A surprise upgrade can break plugins; pin a long-term support version and upgrade on purpose.
- Leaving port 8080 open to everyone. Put Jenkins behind a firewall or a reverse proxy with login, and never expose it to the whole internet.
- Ignoring the admin password. The password printed in the log is the only way in before setup finishes, so copy it before the log scrolls past.
- Forgetting backups. A volume is not a backup. Copy it to another host on a schedule, and test restoring it at least once.
A related trap is giving Jenkins more work than one host can handle. If builds queue for hours, add an agent on a second host rather than adding RAM to the same box. The same pattern applies to other tools run this way, as in the guide to running SonarQube with Docker Compose.
How do you keep it running well?
You keep a Compose-based Jenkins healthy by upgrading on a schedule, watching disk use, and keeping the plugin list short.
- Upgrade monthly. Stop the container, back up the volume, change the image tag, and start again. Test one job before calling it done.
- Watch disk space. Set a build retention policy, such as keeping the last 20 builds per job, so old logs do not fill the disk.
- Prune plugins. Remove plugins you never use; each one is a thing that can break on upgrade.
- Back up the volume weekly. Copy it off the host, and restore it on a spare machine once a quarter to prove the backup works.
- Put it behind HTTPS. A reverse proxy with a certificate keeps passwords and tokens off plain HTTP.
When the single host stops being enough, the usual next step is agents on separate machines, then a move to a cluster. The compose file stays useful either way, since it documents exactly how the controller is configured.
Key takeaways
- Docker Compose runs Jenkins in one container with its data in a named volume
- Pin a long-term support image tag and upgrade on purpose, never by accident
- The initial admin password is printed in the container log
- Put Jenkins behind a firewall or HTTPS, never open to the whole internet
- Back up the volume on a schedule and test restoring it
- Set build retention so old logs do not fill the disk
Frequently asked questions
Do I need Docker Compose, or is plain Docker enough?
Plain Docker works for a single container, but Compose records the image, ports, volume and restart policy in one file that anyone can read and re-run. That file becomes the documentation of your Jenkins setup, which is why most teams prefer it even for one service.
How much RAM does Jenkins need in Docker?
Jenkins itself runs well on 2 GB of RAM for a small team, but builds run in the same container by default, so give the host 4 GB or more once you have several jobs. If builds run out of memory, move them to agents on separate hosts rather than adding RAM forever.
What happens if I delete the container?
Nothing is lost if the data is in a named volume, since the volume is separate from the container. You can delete the container, pull a new image and start it with the same volume, and all jobs, plugins and history come back.
Can Jenkins run on Windows or macOS with Compose?
Yes, Docker Desktop on Windows and macOS runs the same compose file. The paths and the way you open ports differ slightly, and performance is lower than on Linux, so most teams run the real server on Linux and use a laptop install only for testing.
How do I add build tools like Maven or Node?
Install them as Jenkins tools in the global tool settings, or run builds in agent containers that already have them. The second option keeps the controller clean and lets each job use the exact version it needs.
How do I upgrade Jenkins safely?
Stop the container, copy the volume to a backup, change the image tag in the compose file, and start it again. Check the upgrade guide for the new version first, since some releases need a plugin update at the same time.