Operations 13 min read

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.

360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
How to Build a Jenkins‑Docker CI/CD Pipeline from Scratch

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 jenkins

After 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 jenkins

Create a workspace directory and assign ownership:

mkdir /data/jenkins
chown jenkins.jenkins /data/jenkins

Add 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_keys

Docker 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.

Docker plugins overview
Docker plugins overview

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.

QR code
QR code
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockerci/cdAutomationDevOpsPipelineJenkins
360 Zhihui Cloud Developer
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.