Running Jenkins in a container keeps the server itself disposable: its jobs, plugins and credentials live in a Docker volume, so the container can be upgraded or replaced without losing anything. This guide sets that up on an Ubuntu server and prepares Jenkins to build and deploy Docker-based applications.
Before you start
You’ll need an Ubuntu server (20.04 or 22.04 recommended), root or sudo access, and an internet connection.
Install Docker
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable --now docker
docker --version
Give Jenkins a Docker client
The official jenkins/jenkins:lts image does not include the Docker CLI. To let pipelines run docker build, extend the image with the client — the daemon itself stays on the host:
FROM jenkins/jenkins:lts
USER root
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl \
&& install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc \
&& echo "deb [signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
> /etc/apt/sources.list.d/docker.list \
&& apt-get update && apt-get install -y docker-ce-cli \
&& rm -rf /var/lib/apt/lists/*
USER jenkinsdocker build -t aviox/jenkins-docker .
Run the container
docker run -d \
--name jenkins \
--restart unless-stopped \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
--group-add $(stat -c '%g' /var/run/docker.sock) \
aviox/jenkins-docker
| Option | Purpose |
|---|---|
-p 8080:8080 | The Jenkins web interface |
-p 50000:50000 | Communication with Jenkins agents |
-v jenkins_home:… | Persistent storage for jobs, plugins and credentials |
-v /var/run/docker.sock:… | Lets Jenkins drive the host’s Docker daemon |
--group-add … | Grants the jenkins user permission to use that socket |
The Docker socket is root access
Anything that can talk to
docker.sockcan control the host. Restrict who can create and edit jobs, keep plugins updated, and consider dedicated build agents for untrusted code.
Keep reading — it’s free
The remaining 1 min of this story is for Dispatch subscribers. Subscribing takes one field, and the whole story opens right here.
Subscribe to read the rest
Free. One email when there’s something worth reading.
Originally published at Aviox Blogs engineering handbook.


