Operations 7 min read

One-Click Jenkins + Docker + Spring Boot Automated Deployment Guide

This tutorial provides a complete step‑by‑step guide to set up a Jenkins server inside Docker on CentOS, configure Maven and plugins, create a pipeline that builds a Spring Boot project, builds a Docker image with a Dockerfile, and runs the container automatically, covering all common pitfalls.

Architecture Digest
Architecture Digest
Architecture Digest
One-Click Jenkins + Docker + Spring Boot Automated Deployment Guide

Environment : CentOS 7 with Git (Gitee).

Brief steps: install Docker, install Jenkins, configure Jenkins, create a job, build, test, and run the Spring Boot project.

Install Docker

Update yum packages, remove old Docker versions, install required utilities, add Docker CE repository, and install 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   # install the latest stable version
systemctl start docker
systemctl enable docker
docker version

Install Jenkins

Run Jenkins in Docker (Blue Ocean image) and expose 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/blueocean

Access Jenkins at http://{JENKINS_HOST_IP}:8080, unlock using the password from cat /var/lib/jenkins/secrets/initialAdminPassword, install recommended plugins, and create an admin user.

System Configuration

Install required plugins: Maven Integration, Publish Over SSH (optional), Gitee (if using Gitee). Configure Maven under Manage Jenkins → Global Tool Configuration.

Create Job

Create a new Freestyle project, set Git repository URL and credentials, add a build step "Invoke top‑level Maven targets" with goal clean install -Dmaven.test.skip=true, and save.

Test Build

Trigger the build, monitor console output, and verify the generated JAR file. If the first build fails to download dependencies, re‑run the build.

Run Project

Because Jenkins and the project run on the same host, a shell script will build a Docker image and run the container.

Dockerfile

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"]

Jenkins Job Configuration

After the Maven build, add a shell step to stop/remove any existing container, build the 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

Note: avoid using docker logs -f in the build step because it blocks the job.

Verification

Check running containers with docker ps, view logs via docker logs {container_name}, and access the application in a browser at http://{HOST_IP}:8888.

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.

Backendci/cdautomationDevOpsSpring BootJenkins
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

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.