Sources:
Downloading the Docker image
From https://hub.docker.com/r/jenkinsci/jenkins/:
- To use the latest LTS: docker pull jenkinsci/jenkins:lts
- To use the latest weekly: docker pull jenkinsci/jenkins
Running jenkins:
docker run --name jenkinsci -p 8080:8080 --env JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true" -v /var/jenkins_home:/var/jenkins_home jenkinsci/jenkins:lts
Now lets run through some of the arguments:
-p: the Port Jenkins will be running on
–env: can set environment variables. In my example I’am adding STARTLS support to the mailer jenkins uses.
-v: binds the folder ‚/var/jenkins_home‘ on the host machine with the /var/jenkins_home on the vm. THis is the place where all jenkins data will be stored. If you don’t use this your whole data could be wiped upon updating jenkins.
systemd Service
[Unit]
Description=Jenkins CI (Docker)
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start -a jenkinsci
ExecStop=/usr/bin/docker stop -t 2 jenkinsci
[Install]
WantedBy=multi-user.target



