One‑Click Jenkins & Docker CI/CD for Spring Boot Projects
This guide walks you through installing Docker and Jenkins on CentOS 7, configuring Jenkins plugins, creating a freestyle job that builds a Spring Boot application with Maven, and deploying it via a Dockerfile for fully automated one‑click deployment.
This article demonstrates how to set up a one‑click automated deployment pipeline for a Spring Boot project using Docker and Jenkins on a CentOS 7 host.
Install Docker
Update yum packages: yum update Remove old Docker versions:
yum remove docker docker-common docker-selinux docker-engineInstall required utilities:
yum install -y yum-utils device-mapper-persistent-data lvm2Add Docker CE repository:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repoInstall Docker CE: yum install docker-ce Start Docker and enable on boot:
systemctl start docker
systemctl enable dockerVerify installation:
docker versionInstall Jenkins
Run Jenkins container:
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://{host_ip}:8080 and complete the initial setup.
Unlock Jenkins by retrieving the admin password from the container:
docker exec -it jenkins bash
cat /var/lib/jenkins/secrets/initialAdminPasswordInstall recommended plugins, including Maven Integration, Publish Over SSH, and Gitee (if needed).
Create an admin user.
System Configuration
Install required plugins: Maven Integration, Publish Over SSH, Gitee, etc.
Configure Maven under “Global Tool Configuration”.
Create a Jenkins Job
Create a new “Freestyle project”.
Configure source code management with Git, providing repository URL and credentials.
Add a build step “Invoke top‑level Maven targets” with goal clean install -Dmaven.test.skip=true.
Save the job.
Test Build
Trigger a build and monitor the console output to ensure the JAR is produced.
If dependencies fail to download on the first attempt, rebuild.
Locate the workspace at /var/jenkins_home/workspace and verify the JAR.
Run the Project
Create a Dockerfile in the Spring Boot project root:
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"]Add a build step in the Jenkins job to build and run the Docker image:
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:latestSave and build the job.
Verify the container is running with docker ps and view logs with docker logs.
Access the application in a browser at http://{host_ip}:8888.
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.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
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.
