One-Click Jenkins + Docker + Spring Boot Deployment: Step‑by‑Step Guide
This tutorial walks you through setting up a complete Jenkins‑Docker‑SpringBoot CI/CD pipeline on CentOS 7, covering Docker and Jenkins installation, plugin configuration, Maven setup, job creation, automated building, Docker image creation, and final verification, all with practical command examples.
Environment
CentOS 7 with Git (Gitee) is used as the base system.
Install Docker
Install the community edition (CE) of Docker.
Update yum packages
yum updateRemove old Docker versions (if any)
yum remove docker docker-common docker-selinux docker-engineInstall required packages
yum install -y yum-utils device-mapper-persistent-data lvm2Add Docker repository
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repoInstall Docker CE
yum install docker-ce # installs the latest stable version (e.g., 17.12.0)
# or install a specific version, e.g.:
# yum install docker-ce-17.12.0.ceStart Docker and enable on boot
systemctl start docker
systemctl enable dockerVerify installation
docker versionInstall Jenkins
Run Jenkins in a Docker container (Blue Ocean image). Ensure port 8080 is free.
docker run --name jenkins -u root --rm -d -p 8080:8080 -p 50000:50000 \
-v /var/jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkinsci/blueoceanAccess Jenkins at http://{SERVER_IP}:8080 (initial setup may take a few minutes).
Initialize Jenkins
Follow the official guide at https://www.jenkins.io to unlock Jenkins, retrieve the initial admin password with:
docker exec -it jenkins bash
cat /var/lib/jenkins/secrets/initialAdminPasswordEnter the password in the web UI.
Install plugins
Select “Install suggested plugins”. Required plugins include:
Maven Integration
Publish Over SSH (optional)
Gitee (if using Gitee, Git support is built‑in)
Create admin user
Remember the credentials you set.
System Configuration
Configure Maven
Navigate to Manage Jenkins → Global Tool Configuration → Maven and add a Maven installation.
Create Job
New Job
Click “New Item”, enter a job name, and choose “Freestyle project”.
Source Code Management
Select Git, provide the repository URL, and add credentials.
Build Triggers
Configure desired triggers (e.g., poll SCM, webhook).
Build Steps
Add a “Invoke top‑level Maven targets” step with the goal: clean install -Dmaven.test.skip=true This compiles the project and produces the JAR.
Save
Click “Save”.
Test Build
Click “Build Now”, then open the build console output to verify that the JAR is created. If the first build fails to download dependencies, retry.
Locate Workspace
cd /var/jenkins_home/workspace
lsRun Project
Because Jenkins and the application run on the same server, a shell script launches the Docker container after the image is built.
Dockerfile
FROM jdk:8
VOLUME /tmp
ADD target/zx-order-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8888
ENTRYPOINT ["Bash","-DBash.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.profiles.active=prd"]Jenkins Job Adjustments
After the Maven build, add shell commands to stop/remove any existing container, build a new image, and run it:
cd /var/jenkins_home/workspace/zx-order-api
docker stop zx-order || true
docker rm zx-order || true
docker rmi zx-order || true
docker build -t zx-order .
docker run -d -p 8888:8888 --name zx-order zx-order:latestNote: using docker logs -f in the job will block the build; avoid it. The || true pattern ensures the script continues even if a command fails.
Build and Verify
Run the Jenkins job, then check the console output for success messages.
docker ps # verify container is running
docker logs zx-order # view application logsOpen a browser and navigate to http://{SERVER_IP}:8888 to confirm the Spring Boot application is serving correctly.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
