Install Jenkins by Docker
You are a DevOps fresher and want to practice with Jenkins for CI/CD, but you remember you need install Java, service config, port mapping, etc. A huge messy things you need to do first, this post is for you

Environment Setup
To begin, you need two things:
- Install docker
- At least 4GB RAM to run
Quick check:
docker --versiondocker ps
If two commands above run without zero, READY TO START
Install Jenkins by docker run
Step 1: Create folder to store Jenkins data
mkdir ~/jenkins_home
This folder will store Jenkins configuration, plugin, job, credential, etc. It's make sure the data/config is "safe" when stop/remove container
Step 2: Run Jenkins container
Open command prompt / terminal and run
docker run -d \
--name jenkins \
-p 8080:8080 \
-p 50000:50000 \
-v ~/jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts
Quick explain:
-
-p 8080:8080: mapping port8000in container to port8000in host machine -
-p 50000:50000: port connect for agent (I will write about it in other post) -
-v ~/jenkins_home:/var/jenkins_home: mountjenkins_homefolder into container -
jenkins/jenkins:lts: the latest Jenkins image
Install Jenkins with docker-compose
If you want deploy Jenkins like IaC (Infrastructure As Code), docker-compose is the best suite
Step 1: Create project folder
mkdir jenkins-docker
cd jenkins-docker
mkdir jenkins_home
Bước 2: Create file docker-compose.yml
version: "3.8"
services:
jenkins:
image: jenkins/jenkins:lts
container_name: jenkins
ports:
- "8080:8080"
- "50000:50000"
volumes:
- ./jenkins_home:/var/jenkins_home
restart: unless-stopped
Some setting optional:
restart: unless-stopped: Jenkins will start automatically after server restart- Put
./jenkins_homefolder in the same directory of file compose, easy to backup.
Step 3: Start service
docker compose up -d
Older version:
docker-compose up -d
Check:
docker compose ps
docker compose logs -f jenkins
If you see Jenkins log “Jenkins is fully up and running”, you're all set.
Get admin password
Access to jenkins container and run:
cat jenkins_home/secrets/initialAdminPassword
How to backup?
We usually use the "old" but most efficient:
- Stop container or at least, stop an heavy job when backup
- Zip
jenkins_homefolder (or volume snapshot if use cloud storage)