Step-by-Step Guide to Automate Spring Boot Deployment with Jenkins, Docker, and Maven
This tutorial explains how to set up a complete CI/CD pipeline on CentOS 7 by installing Docker and Jenkins, configuring Maven, creating Jenkins jobs, building a Spring Boot application into a Docker image, and running the container, with detailed commands and screenshots for each step.
This article provides a comprehensive, hands‑on guide for automatically deploying a Spring Boot project using Jenkins, Docker, and Maven on a CentOS 7 environment.
Environment : CentOS 7 with Git (Gitee) installed.
1. Install Docker CE
yum updateyum remove docker docker-common docker-selinux docker-engineyum install -y yum-utils device-mapper-persistent-data lvm2yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repoyum install docker-cesystemctl start dockersystemctl enable dockerdocker version2. Install Jenkins (Docker image)
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 and wait for initialization.
2.1 Unlock Jenkins
Enter the container: docker exec -it {JENKINS_CONTAINER} bash Retrieve the admin password: cat /var/lib/jenkins/secrets/initialAdminPassword Paste the password into the web UI.
2.2 Install Plugins
Choose “Install suggested plugins”.
After installation, create the admin user.
3. System Configuration
Navigate to Manage Jenkins → Manage Plugins → Available and install:
4. Maven Configuration
Go to Manage Jenkins → Global Tool Configuration and set up Maven installation.
5. Create a Jenkins Job
Click “New Item”, name the job, select “Freestyle project”.
In Source Code Management , choose Git, enter the repository URL and credentials.
In Build Triggers , add a build step “Invoke top‑level Maven targets” with goal clean install -Dmaven.test.skip=true.
Save the job.
6. Test Build
Click “Build Now”.
Check the console output to ensure a JAR is produced.
7. Run the Project
Because the Jenkins server and the application share the same host, a shell script builds a Docker image and runs it.
7.1 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"]7.2 Jenkins Job Commands
cd /var/jenkins_home/workspace/zx-order-apidocker stop zx-order || truedocker rm zx-order || truedocker rmi zx-order || truedocker build -t zx-order .docker run -d -p 8888:8888 --name zx-order zx-order:latestNote: Adding || true prevents the script from failing if a command does not succeed.
8. Verify Deployment
Run docker ps to see the running container.
Check logs with docker logs zx-order.
Open a browser and navigate to http://{HOST_IP}:8888 to confirm the application is reachable.
The article concludes with screenshots of successful Jenkins console output and instructions for further testing.
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.
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.
