Operations 7 min read

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.

Programmer DD
Programmer DD
Programmer DD
How to Automate Spring Boot Deployment with Jenkins and Docker in One Click

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/blueocean

Access 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.

Jenkins unlock screen
Jenkins unlock screen

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.

Jenkins plugin installation
Jenkins plugin 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.

Create Jenkins job
Create Jenkins 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.

Jenkins build output
Jenkins build output

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:latest

Verify the container is running with docker ps and check logs with docker logs zx-order.

Jenkins run output
Jenkins run output
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockerci/cdAutomationmavenSpring BootJenkins
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.