Automate Spring Boot Deployment with Jenkins, Docker, and One‑Click CI/CD
This guide walks through installing Docker and Jenkins on CentOS 7, configuring Jenkins with necessary plugins, setting up Maven, creating a Jenkins pipeline to pull, build, and containerize a Spring Boot project, and finally testing and running the application automatically, providing a complete one‑click CI/CD solution.
Install Docker CE on CentOS 7:
Update yum packages.
Remove old Docker versions.
Install required utilities: yum install -y yum-utils device-mapper-persistent-data lvm2 Add Docker repository:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repoInstall Docker: yum install docker-ce Start and enable Docker: systemctl start docker and systemctl enable docker Verify installation with docker version.
Install Jenkins using Docker:
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 retrieve the initial admin password with
docker exec -it jenkins cat /var/lib/jenkins/secrets/initialAdminPassword.
Complete Jenkins initialization:
Enter the password.
Install recommended plugins.
Create an admin user.
Install additional plugins such as Maven Integration, Publish Over SSH, and Gitee (if needed).
Configure Maven in Jenkins (Global Tool Configuration) and set up a new freestyle job:
Enable Git source management with 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 the pipeline by building the job and checking the console output for a successful JAR package.
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"]Update the Jenkins job to build the Docker image and run the 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:latestVerify the deployment with docker ps, docker logs, and by accessing http://{host_ip}:8888 in a browser.
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.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
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.
