Operations 8 min read

Step-by-Step Guide to Jenkins + Docker + Spring Boot One-Click Automatic Deployment

This tutorial walks through setting up a CentOS 7 environment, installing Docker and Jenkins, configuring Jenkins plugins and Maven, creating a freestyle job that pulls a Spring Boot project from Gitee, builds it with Maven, packages it into a Docker image via a Dockerfile, runs the container, and verifies the deployment, providing all commands and screenshots for a complete CI/CD pipeline.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Step-by-Step Guide to Jenkins + Docker + Spring Boot One-Click Automatic Deployment

Environment

CentOS 7 with Git (Gitee) is used as the base platform.

The implementation steps are: install Docker, install Jenkins, configure Dockerfile and shell scripts to automatically pull, build, and run the Spring Boot project.

Install Docker

Update yum packages and remove any old Docker versions:

yum update
yum remove docker docker-common docker-selinux docker-engine

Install required utilities and set up the Docker repository:

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install Docker CE, start it, enable it on boot, and verify the installation:

yum install docker-ce
systemctl start docker
systemctl enable docker
docker version

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

Access Jenkins at http://{JENKINS_HOST_IP}:8080, retrieve the initial admin password, and complete the setup wizard.

Install Plugins

Install the recommended plugins, then add the following optional plugins:

Maven Integration

Publish Over SSH (if remote deployment is needed)

Gitee plugin (if using Gitee, Git is sufficient)

Configure Maven

Navigate to Manage Jenkins → Global Tool Configuration and add a Maven installation.

Create a Jenkins Job

Create a new freestyle project, give it a name, and configure the following sections:

Source Code Management

Select Git, enter the Gitee repository URL, and add the appropriate credentials.

Build Triggers

Enable the desired trigger (e.g., poll SCM or webhook).

Build Steps

Add a Maven build step with the goal:

clean install -Dmaven.test.skip=true

Post‑Build Actions

Optionally add steps to publish artifacts or trigger downstream jobs.

Test the Job

Click Build Now, monitor the console output, and ensure the JAR is produced without errors.

Run the 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 ["Bash","-DBash.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.profiles.active=prd"]

Update the Jenkins job to add a shell step that builds the Docker image and runs the container:

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

Note: the || true pattern prevents the job from failing if a command does not find an existing container or image.

Verification

Check the running containers and logs:

docker ps
docker logs zx-order

Finally, open a browser and navigate to http://{HOST_IP}:8888 to confirm the application is running.

End of tutorial.

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/cdautomationDevOpsSpring BootJenkins
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

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.