One‑Click Jenkins + Docker + Spring Boot Deployment: Step‑by‑Step Guide
This tutorial walks you through setting up a complete CI/CD pipeline on CentOS 7 using Docker, Jenkins, and Spring Boot, covering Docker installation, Jenkins container deployment, plugin and Maven configuration, job creation, Dockerfile setup, and automated project build and run.
This article demonstrates a complete one‑click Jenkins + Docker + Spring Boot deployment pipeline on CentOS 7, covering environment setup, Docker installation, Jenkins container deployment, plugin configuration, Maven setup, job creation, build triggers, Dockerfile creation, and running the application.
Environment
CentOS 7 + git (gitee).
Install Docker
Update yum packages
yum updateRemove old Docker versions
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 (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 and follow the initialization steps on the official site.
Unlock Jenkins
Enter the container: docker exec -it jenkins bash Retrieve the initial admin password:
cat /var/lib/jenkins/secrets/initialAdminPasswordInstall Plugins
Choose “Install suggested plugins” and then create an admin user.
System Configuration
Install required plugins: Maven Integration, Publish Over SSH (optional), Gitee (if using Gitee).
Configure Maven
Navigate to Manage Jenkins → Global Tool Configuration → Maven and set up Maven installation.
Create Job
New Job
Create a “Freestyle project” with a suitable name.
Source Code Management
Select Git, enter 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 goals such as:
clean install -Dmaven.test.skip=trueSave
Save the job configuration.
Test Build
Click “Build Now” and monitor the console output. The first run may download dependencies; a second run should succeed.
Check Workspace
cd /var/jenkins_home/workspace
lsRun Project
Since Jenkins and the project share the same server, use a shell script to build a Docker image and run the container.
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, and rebuild the Docker container:
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: Avoid using docker logs -f in the build step, and use || true to prevent failures when the image does not yet exist.
Verify
docker ps # confirm container is running
docker logs zx-order # view application logsOpen http://{SERVER_IP}:8888 in a browser to test the deployed Spring Boot service.
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.
