How to Deploy Jenkins on a VPS
Updated Nov 2026
verified on Ubuntu 26.04 · Nov 2026Self-host Jenkins LTS on a VPS with Docker Compose and Caddy HTTPS: unlock it safely, back up JENKINS_HOME and the master key separately, restore, and upgrade.
- A VPS with 2 GB+ RAM (Jenkins documents 256 MB as the minimum and 4 GB+ for a small team)
- A fresh Ubuntu 26.04 server with root/sudo SSH access
- A domain or subdomain you can point at the server
What Jenkins is
Jenkins is a long-established, MIT-licensed automation
server for building, testing and deploying software. It is extended through
plugins and configured with pipelines written as code in a Jenkinsfile. This
guide runs the current LTS image with Docker Compose, puts Caddy in front for
HTTPS, and covers a backup you restore and an upgrade path.
It sets up the controller only. Builds that need Docker or heavy toolchains belong on separate agents; do not mount the host's Docker socket into this container, because anyone who can edit a pipeline would then control the server.
Server sizing
The Jenkins documentation gives 256 MB of RAM and 1 GB of disk as the bare minimum, recommends at least 10 GB of disk when running in a container, and suggests 4 GB+ RAM and 50 GB+ disk for a small team. On the catalog's test box an idle install used about 492 MB of RAM and 758 MB of disk. Builds, plugins and build history add to both.
Prepare the server
Update the system, install the tools this guide uses, and open only SSH and the two web ports:
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install -y curl openssl ufw dnsutils jq
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw --force enable
If you're logged in as root, create a non-root sudo user and continue as that user:
adduser deploy
usermod -aG sudo deploy
A published container port goes around ufw on a Docker host, so only what
should be public gets published below.
Paid link — we earn a commission if you shop through it.
Install Docker
The convenience script installs Docker Engine and the Compose plugin (the Docker and Compose on Ubuntu guide covers the details):
command -v docker >/dev/null || curl -fsSL https://get.docker.com | sudo sh
sudo docker compose version
Install Jenkins
The image tag is pinned to an exact LTS release. The web port is bound to loopback only, and Caddy is the public door. Port 50000 is not published: it is only needed for inbound TCP agents, and agents can connect over WebSocket through HTTPS instead. Set your hostname first:
mkdir -p ~/jenkins && cd ~/jenkins
echo "DOMAIN=jenkins.example.com" > .env
cat > compose.yaml <<'EOF'
services:
jenkins:
image: jenkins/jenkins:2.580.3-lts-jdk21
restart: unless-stopped
ports: ["127.0.0.1:8080:8080"]
volumes: ["jenkins_home:/var/jenkins_home"]
caddy:
image: caddy:2
restart: unless-stopped
ports: ["80:80", "443:443"]
environment:
DOMAIN: ${DOMAIN}
volumes: ["./Caddyfile:/etc/caddy/Caddyfile:ro", "caddy_data:/data"]
volumes:
jenkins_home:
name: jenkins_home
caddy_data:
EOF
cat > Caddyfile <<'EOF'
{$DOMAIN} {
reverse_proxy jenkins:8080
}
EOF
sudo docker compose up -d
for i in $(seq 1 60); do
sudo docker compose exec -T jenkins test -s /var/jenkins_home/secrets/initialAdminPassword && break
sleep 3
done
curl -s -o /dev/null -w 'login page: %{http_code}\n' --retry 20 --retry-delay 3 --retry-all-errors -f http://127.0.0.1:8080/login
HTTPS + domain
Create an A record for your hostname pointing at the server's public IP and confirm it resolves, because Caddy needs that to get a certificate (see Automatic HTTPS with Caddy):
dig +short jenkins.example.com
Then check that HTTPS answers, retrying while the certificate is issued:
. ~/jenkins/.env
curl -s -o /dev/null -f --retry 30 --retry-delay 5 --retry-all-errors \
-w '%{http_code} verify=%{ssl_verify_result}\n' "https://$DOMAIN/login"
200 verify=0 means the certificate is valid.
Secure first login
Jenkins starts locked. The unlock key is a random password written inside the container:
cd ~/jenkins
sudo docker compose exec -T jenkins cat /var/jenkins_home/secrets/initialAdminPassword
Open https://jenkins.example.com, paste it, and finish the setup wizard right
away:
- Install the suggested plugins, or pick your own set.
- Create your own admin user instead of continuing as
adminwith the unlock key. - Confirm the Jenkins URL is your
https://address. It is used in links and webhooks.
Later, once you have an agent connected, set the built-in node to 0 executors (Manage Jenkins > Nodes) so builds never run on the controller.
Backups
Everything is in JENKINS_HOME, the jenkins_home volume. The Jenkins
documentation says not to keep secrets/master.key in the regular backup:
it decrypts the stored credentials, so keep it somewhere separate and safer.
war, cache and workspace can be rebuilt and are left out. Stop Jenkins so
the files are consistent:
cd ~/jenkins
sudo docker compose stop jenkins
( umask 077
sudo docker run --rm -v jenkins_home:/h:ro alpine:3 tar czf - -C /h \
--exclude=./war --exclude=./cache --exclude=./workspace --exclude=./secrets/master.key . > ~/jenkins-home.tar.gz
sudo docker run --rm -v jenkins_home:/h:ro alpine:3 cat /h/secrets/master.key > ~/jenkins-master.key
tar czf ~/jenkins-config.tar.gz compose.yaml Caddyfile .env )
sudo docker compose start jenkins
tar tzf ~/jenkins-home.tar.gz | grep -c . && ls -l ~/jenkins-home.tar.gz ~/jenkins-master.key ~/jenkins-config.tar.gz
Copy these off the server, with the key stored apart from the archive.
To restore, empty the volume, unpack the archive and put the key back, owned by
the jenkins user (UID 1000). This replaces the current JENKINS_HOME; on
a new server, unpack the config archive and run sudo docker compose up --no-start
first:
cd ~/jenkins
test -s ~/jenkins-home.tar.gz && test -s ~/jenkins-master.key &&
sudo docker compose stop jenkins &&
sudo docker run --rm -v jenkins_home:/h alpine:3 find /h -mindepth 1 -delete &&
sudo docker run --rm -i -v jenkins_home:/h alpine:3 tar xzf - -C /h < ~/jenkins-home.tar.gz &&
sudo docker run --rm -i -v jenkins_home:/h alpine:3 sh -c \
'cat > /h/secrets/master.key && chown 1000:1000 /h/secrets/master.key && chmod 600 /h/secrets/master.key' < ~/jenkins-master.key &&
sudo docker compose start jenkins &&
curl -s -o /dev/null -w 'after restore: %{http_code}\n' -f --retry 30 --retry-delay 3 --retry-all-errors http://127.0.0.1:8080/login
Then sign in and check that your jobs are there and a build that uses a stored credential still works.
Upgrades
Read the LTS upgrade guide for
every release between yours and the target, take a backup, then change the
image tag in compose.yaml and recreate:
cd ~/jenkins
sudo docker compose pull
sudo docker compose up -d
sudo docker compose logs --tail 20 jenkins
Afterwards, check Manage Jenkins > Plugins for plugin updates. Keep the tag
pinned to a full version such as 2.580.3-lts-jdk21, not lts.
Troubleshooting
502 from Caddy. Jenkins is still starting or has stopped; read
sudo docker compose logs jenkins.
"It appears that your reverse proxy set up is broken." The Jenkins URL in Manage Jenkins > System does not match the address in your browser.
Credentials fail after a restore. secrets/master.key is missing or belongs
to a different instance.
Builds run out of memory. Move them to an agent, or use a larger server.
Verification + next steps
This guide's run checked HTTPS, the unlock password, and a backup and restore that brought back a job and an encrypted secret. The setup wizard in the browser, agents and a version change were not tested.
You're done when https://jenkins.example.com loads over a valid certificate,
you sign in with your own admin user, and you have restored a backup once. Next,
add an agent and move your pipelines into Jenkinsfiles. See the
Jenkins entry for catalog details and
Best VPS for self-hosting for server picks.
Next steps
Common questions
How long does it take to follow "How to Deploy Jenkins on a VPS"?
We estimate about 30 minutes of hands-on time for "How to Deploy Jenkins on a VPS"; this is an editorial estimate, not a measurement.
Was the "How to Deploy Jenkins on a VPS" guide tested?
The "How to Deploy Jenkins on a VPS" guide was verified end-to-end on Ubuntu 26.04 (Nov 2026).