How to Automate Spring Boot Deployment with Jenkins and Docker in One Click
This step‑by‑step guide shows how to install Docker and Jenkins on CentOS, configure Jenkins plugins and Maven, create a freestyle job that pulls a Spring Boot project from Git, builds it with Maven, packages it into a Docker image, and runs the container automatically.
1. Install Docker
Update yum, remove any old Docker packages, install required utilities, add the Docker CE repository, then install Docker CE. Start Docker, enable it to start on boot, and verify the installation with docker version.
2. Install Jenkins
Run Jenkins in a Docker container:
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 http://{SERVER_IP}:8080, unlock Jenkins by retrieving the initial admin password from /var/lib/jenkins/secrets/initialAdminPassword, install the recommended plugins, and create an admin user.
3. System Configuration
Install required plugins such as Maven Integration , Publish Over SSH , and Gitee (if using Gitee). Configure Maven in Manage Jenkins → Global Tool Configuration by adding a Maven installation.
4. Create Job
Create a new freestyle project, set the Git repository URL and credentials, add a build step that runs Maven: clean install -Dmaven.test.skip=true Save the job.
5. Test Build
Trigger the build, view the console output to ensure the JAR is produced, and check the workspace for the generated artifact.
6. Run 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 ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.profiles.active=prd"]Modify the Jenkins job to stop/remove any existing container, build a new Docker image, and run it:
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 container is running with docker ps and check logs with docker logs zx-order.
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.
