Deploying Jenkins with Docker: Configuring Static and Dynamic Slaves
This guide explains how to deploy Jenkins using Docker, set up both static and dynamic Docker‑based slaves, configure plugin sources, adjust certificates, and fine‑tune Docker Cloud settings for reliable CI/CD pipelines.
This article demonstrates a step‑by‑step deployment of Jenkins LTS via Docker, beginning with pulling the official image from Docker Hub and launching the container with appropriate ports and a persistent volume.
Key environment variables are defined to configure Jenkins home and agent ports:
ARG http_port=8080
ARG agent_port=50000
ARG JENKINS_HOME=/var/jenkins_home
ARG REF=/usr/share/jenkins/ref
ENV JENKINS_HOME=/var/jenkins_home
ENV JENKINS_SLAVE_AGENT_PORT=50000The container is started with:
docker run --name jenkins -itd \
-p 8081:8080 \
-p 50000:50000 \
-v ~/jenkins:/var/jenkins_home \
jenkins/jenkins:ltsAfter obtaining the initial admin password from the logs, the installation wizard is completed and an admin user is created.
To avoid plugin download failures, the Jenkins update center URL is overridden by editing hudson.model.UpdateCenter.xml:
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>https://updates.jenkins-zh.cn/update-center.json</url>
</site>
</sites>A custom certificate is added to ${JENKINS_HOME}/war/WEB-INF/update-center-rootCAs/ to trust the new update source.
Static slave configuration is performed by adding a new node in Jenkins, setting the remote root directory, and launching the agent with the JNLP command:
java -jar agent.jar \
-jnlpUrl http://127.0.0.1:8081/computer/build01/slave-agent.jnlp \
-secret dcc50b0650c1deb806f1e9b855527b83c57df1fd6363ca6e2f814b0b1d273c54 \
-workDir "/home/jenkins"The corresponding Docker image for the JNLP slave is pulled and tested:
docker pull jenkins/jnlp-slave:alpine docker run -it jenkins/jnlp-slave:alpine -url http://192.168.1.101:8081 dcc50b0650c1deb806f1e9b855527b83c57df1fd6363ca6e2f814b0b1d273c54 build01Dynamic slave setup leverages the Docker plugin. Docker remote API access is enabled (example for macOS using bobrik/socat or editing /usr/lib/systemd/system/docker.service on CentOS):
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 2376:2375 bobrik/socat TCP4-LISTEN:2375,fork,reuseaddr UNIX-CONNECT:/var/run/docker.sock [Service]
Type=notify
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sockAfter reloading the daemon, the Docker API can be verified with: #curl -XGET http://127.0.0.1:2376/version Within Jenkins, the Docker Cloud is configured (Docker Host URI, timeouts, container caps, etc.) and Docker Agent templates are defined with labels, image names, remote FS roots, and connection methods (JNLP preferred).
Common issues such as "Read timed out" are addressed by increasing the Read Timeout in the Docker Cloud settings.
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.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
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.
