One‑Click Automated Deployment of a Spring Boot Application Using Jenkins, Docker, and Shell Scripts
This tutorial provides a complete, step‑by‑step guide to automatically deploy a Spring Boot project on CentOS 7 by installing Docker and Jenkins, configuring Maven and required plugins, creating a Jenkins pipeline, building the Docker image, and running the container, while avoiding common pitfalls.
This article demonstrates how to achieve a simple yet comprehensive one‑click automated deployment of a Spring Boot project using Jenkins, Docker, and shell scripts on a CentOS 7 environment with Git (Gitee) as the source repository.
Environment : CentOS 7, Git (Gitee).
Implementation steps :
Install Docker on the host.
Install Jenkins, configure basic information, and use a Dockerfile and shell scripts to pull, build, and run the project automatically.
1. Install Docker
Ensure the yum repository is up to date, remove any old Docker packages, and install the required utilities:
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 version2. Install 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://{JENKINS_HOST_IP}:8080 and follow the initial setup instructions on the official site.
2.1 Unlock Jenkins
# Enter the Jenkins container</code>
<code>docker exec -it {JENKINS_CONTAINER_NAME} bash</code>
<code># View the initial admin password</code>
<code>cat /var/lib/jenkins/secrets/initialAdminPassword2.2 Install Plugins
Select "Install recommended plugins" during the setup.
2.3 Create Admin User
Remember the created administrator credentials.
3. System Configuration
Install required plugins:
Maven Integration
Publish Over SSH (optional)
Gitee plugin (if using Gitee)
Configure Maven under Manage Jenkins → Global Tool Configuration and set the Maven installation path.
4. Create Jenkins Job
1. New Job : Choose a freestyle project and give it a name.
2. Source Code Management : Select Git, provide the repository URL and credentials.
3. Build Triggers : Add a build step to invoke Maven with the goal clean install -Dmaven.test.skip=true. clean install -Dmaven.test.skip=true 4. Save the configuration.
5. Test Build
Click the Build Now button, then monitor the console output to verify that the JAR is produced successfully. If the first build fails to download dependencies, retry.
6. Run the Project
Since Jenkins and the application run on the same host, use a shell script to build the Docker image and run the container.
6.1 Dockerfile
FROM jdk:8
VOLUME /tmp
ADD target/zx-order-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8888
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.profiles.active=prd"]6.2 Jenkins Job Script
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: "|| true" ensures the pipeline continues even if a command fails.
6.3 Verify
docker ps # check the container is running
docker logs zx-order # view application logs
# Open a browser at http://{HOST_IP}:8888 to access the serviceFollowing these steps provides a reliable CI/CD pipeline that automatically builds, packages, and deploys a Spring Boot application 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.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
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.
