Jenkins is an open source, Java-based automation server that offers an easy way to set up a continuous integration and continuous delivery (CI/CD) pipeline.
This tutorial demonstrates the steps of installing Jenkins on Docker Swarm. The Jenkins image that has been used was built with Docker Engine inside and some custom configuration like setting the Jenkins admin user and password, also pre-installed some plugins.
Deploy Jenkins in Docker Swarm

01- First, let’s create a Docker network as below:
# docker network create -d overlay jenkins-net
jmjn9ezjg2ftyuk3f8blaaca0
01- First, create the stack Yaml file as below:
version: '3.7'
services:
jenkins:
image: yallalabs/jenkins:centos
environment:
- JAVA_OPTS=-Djenkins.install.runSetupWizard=false -Dhudson.footerURL=http://yallalabs.com
- JENKINS_USER=CHANGE_ME
- JENKINS_PASS=CHANGE_ME
ports:
- 8080:8080
- 50000:50000
volumes:
- jenkins_data:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
networks:
- jenkins-net
deploy:
mode: replicated
replicas: 1
restart_policy:
condition: on-failure
placement:
constraints:
- node.role == worker
healthcheck:
test: ["CMD-SHELL", "curl -sS http://localhost:8080/login || exit 1"]
interval: 30s
timeout: 10s
retries: 5
volumes:
jenkins_data:
driver: local
driver_opts:
type: "none"
o: "bind"
device: "/jenkinsdata"
networks:
jenkins-net:
driver: overlay
external: true
/jenkinsdata to all the Docker Swarm Workers.
03- Now, let’s deploy the Jenkins Docker stack by running the below command:
# docker stack deploy -c jenkins_stack.yml jenkins-prod
Creating service jenkins-prod_jenkins
04- Finally, let’s check if the stack was deployed successfully:
# docker stack services jenkins-prod
ID NAME MODE REPLICAS IMAGE PORTS
7drve5u4cinx jenkins-prod_jenkins replicated 1/1 yallalabs/jenkins:centos *:8080->8080/tcp, *:50000->50000/tcp
Conclusion
In this tutorial, you have learned how to deploy and run Jenkins on Docker Swarm. What’s Next? You might want to check the following guides:


