One-Click Automated Deployment of Spring Boot with Jenkins and Docker
This tutorial provides a step‑by‑step guide to set up a fully automated CI/CD pipeline on CentOS 7 that installs Docker, deploys Jenkins in a container, configures Maven and required plugins, creates a Jenkins job, builds a Spring Boot application with Dockerfile, and runs the resulting container, all with minimal pitfalls.
This article demonstrates how to create a complete Jenkins + Docker + Spring Boot one‑click automated deployment on a CentOS 7 host.
1. Install Docker
Update the system and remove any old Docker packages, then install the required utilities and Docker CE:
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 (Blue Ocean) in a Docker container, exposing ports 8080 and 50000:
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://{SERVER_IP}:8080 , then unlock it by retrieving the initial admin password:
docker exec -it {JENKINS_CONTAINER} bash cat /var/lib/jenkins/secrets/initialAdminPasswordInstall the recommended plugins, then add Maven Integration, Publish Over SSH (optional), and Gitee plugin if using Gitee.
3. System Configuration
Configure Maven under Manage Jenkins → Global Tool Configuration and set the Maven installation path.
4. Create a Jenkins Job
Create a new freestyle project, configure the Git repository URL and credentials, and add a build step that runs Maven:
clean install -Dmaven.test.skip=trueSave the job.
5. Test the Build
Trigger a build, monitor the console output, and verify that a JAR file is produced.
6. Dockerfile for the Spring Boot Application
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"]7. Jenkins Job – Build and Run 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:latestAfter the job finishes, verify the container is running with docker ps and check its logs with docker logs zx-order . Access the application at http://{SERVER_IP}:8888 .
The article concludes with a reminder to like, share, and follow the author for more Spring Boot and DevOps tutorials.
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.