How to Build a Jenkins‑Docker CI/CD Pipeline from Scratch
This article walks you through the fundamentals of continuous integration, introduces Jenkins and Docker, explains key Jenkins concepts, and provides step‑by‑step commands to deploy Jenkins in Docker, configure master‑slave nodes, install essential Docker plugins, and use the Jenkins Remote API for automation.
Introduction
Continuous Integration (CI/CD) is a software development practice that helps teams integrate and test their work frequently, enabling early detection of integration errors, improving code quality, and reducing fault‑handling costs.
Common CI Tools
Jenkins – the most popular open‑source CI server.
ThoughtWorks GO – built with a CI DNA, supporting "Deployment as pipeline".
Atlassian Bamboo – part of the Atlassian toolchain.
GitLab CI – tightly integrated with GitLab.
Travis CI – designed for open‑source projects, integrates with GitHub.
Buildbot – written in Python.
Our choice is Jenkins, so the following sections focus on Jenkins.
Jenkins Features
Open‑source, widely used for CI and CD.
Extensible via a large ecosystem of plugins; users can also develop custom plugins.
Excellent Docker support through dedicated Docker plugins.
Pipeline support (Jenkins 2.0+) using a Groovy‑based DSL.
Developed in Java.
Jenkins Core Concepts
master – the Jenkins server that parses job scripts, schedules tasks, and manages resources.
agent – executes tasks dispatched by the master.
executor – the compute resource on which a task runs; can be on master or agent.
job – defines a specific build process.
Groovy – a JVM‑based language used by Jenkins for its pipeline DSL.
pipeline – "pipeline as code" that describes CI/CD workflows; consists of nodes, stages, and steps.
Jenkinsfile – a Groovy‑based script that defines a pipeline, similar in spirit to a Dockerfile.
Deploying Jenkins with Docker
Jenkins has a minimal set of components and can be deployed quickly using Docker images. docker search jenkins We select the official Jenkins image and pull it: docker pull jenkins Start the container and bind a host directory for persistent data:
sudo mkdir /var/jenkins
sudo chown 1000:1000 /var/jenkins
sudo docker run -p 8080:8080 -p 50000:50000 -v /var/jenkins:/var/jenkins_home --name my_jenkins -d jenkinsAfter the container starts, Jenkins is reachable at http://<em>host_ip</em>:8080. The host directory /var/jenkins acts as the Jenkins home directory and should be owned by UID 1000.
Configuring Jenkins
Open http://<em>jenkins_master_ip</em>:8080 in a browser to complete the initial setup.
Setting Up a Slave Node
On the slave machine install Java JDK: yum install java-1.8.0-openjdk Create a Jenkins user:
useradd -m jenkins -d /home/jenkins
passwd jenkinsCreate a workspace directory and assign ownership:
mkdir /data/jenkins
chown jenkins.jenkins /data/jenkinsAdd the Jenkins user to the Docker group: usermod -a -G docker jenkins Configure password‑less SSH from master to slave:
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
scp ~/.ssh/id_rsa.pub jenkins@slave_ip:~/.ssh/authorized_keys
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keysDocker Plugins for Jenkins
Several Docker‑related plugins are available; the most commonly used are:
Docker Commons Plugin – manages Docker image and container fingerprints, credentials, and Docker daemon connections.
Docker Pipeline Plugin – builds on Docker Commons to provide pipeline‑level Docker orchestration.
Docker Build Step – adds Docker command support to build steps.
Docker Hub Notification Trigger Plugin – triggers builds when a Docker registry image changes.
CloudBees Docker Build and Publish – builds images from Dockerfiles and pushes them to registries.
CloudBees Docker Custom Build Environment – defines a Docker container as the build environment for freestyle jobs.
Kubernetes Plugin – provisions Jenkins agents dynamically on a Kubernetes cluster.
Using Jenkins Remote API
Jenkins provides a RESTful Remote API. For a Jenkins instance at http://myjenkins.com:8080, the API root is http://myjenkins.com:8080/api.
Example: create a job named my_job by posting its XML configuration:
curl -X POST http://myjenkins.com:8080/createItem?name=my_job \
--user uname:pass \
--data-binary "my_job_config.xml" \
-H "Content-Type: application/xml"After creation, the job can be accessed at http://myjenkins.com:8080/job/my_job and its API at http://myjenkins.com:8080/job/my_job/api/.
Conclusion
This article introduced how to implement a Jenkins‑Docker continuous integration pipeline, covering Jenkins basics, Docker deployment, master‑slave configuration, essential Docker plugins, and basic usage of the Jenkins Remote API. Future topics will explore performance testing, scaling, and high‑availability setups.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
360 Zhihui Cloud Developer
360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
