Automate Spring Boot Deployment with Jenkins and Docker: A Step‑by‑Step Guide
Learn how to set up a complete CI/CD pipeline on CentOS 7 by installing Docker and Jenkins, configuring Maven, creating Dockerfiles, and automating the build, test, and deployment of a Spring Boot application with detailed commands, screenshots, and best‑practice tips.
This article provides a comprehensive, step‑by‑step guide to implementing a one‑click automatic deployment pipeline for a Spring Boot project using Jenkins, Docker, and Maven on a CentOS 7 host.
Install Docker
Ensure yum packages are up to date.
Remove any old Docker versions.
Install required utilities.
Add the Docker CE repository.
Install Docker CE (stable version).
Start Docker and enable it to start on boot.
Verify the installation.
yum update yum remove docker docker-common docker-selinux docker-engine yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce systemctl start docker
systemctl enable docker docker versionInstall Jenkins
Run Jenkins in a Docker container, exposing port 8080 and mounting the Jenkins home directory.
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://{JENKINS_HOST_IP}:8080, retrieve the initial admin password, and complete the setup wizard.
docker exec -it jenkins bash
cat /var/lib/jenkins/secrets/initialAdminPasswordSystem Configuration
Install required plugins: Maven Integration, Publish Over SSH (optional), Gitee (if using Gitee), etc.
Configure Maven under Global Tool Configuration .
Create Jenkins Job
Create a new freestyle project.
Configure source code management with Git and provide repository URL and credentials.
Add a build trigger as needed.
Add a build step to invoke Maven with the goal clean install -Dmaven.test.skip=true.
Save the job.
clean install -Dmaven.test.skip=trueTest Build
Trigger the build, monitor the console output, and ensure the JAR is produced successfully.
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","-c","java -jar /app.jar --spring.profiles.active=prd"]Update the Jenkins job to build the Docker image and run the container:
-t: specify new image name
.: Dockerfile location
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 as it blocks the job.
Verification
Check running containers: docker ps View container logs: docker logs zx-order Access the application in a browser at http://{HOST_IP}:8888.
All steps together provide a reproducible CI/CD workflow for Spring Boot applications using Jenkins and Docker.
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.
