Centos8.3, docker deployment springboot project actual case analysis

Centos8.3, docker deployment springboot project actual case analysis

introduction

Currently, k8s is very popular, and I bought a book to learn about it. However, k8s requires the operation and maintenance of hundreds or even thousands of servers. For applications with only a few servers, using k8s is a bit like using a cannon to kill a mosquito. The operation and maintenance of applications with only a few servers using traditional tomcat deployment is cumbersome and inefficient. It takes more than ten minutes to deploy a service. Using jenkins for deployment is too complicated. After considering for a long time, I chose to use docker+dockerFile for deployment. This deployment method is simple and efficient.

Docker installation

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun #One-click installation script systemctl enable docker.service #Set docker to start systemctl restart docker.service #Start docker service

Open Docker remote access port

Edit the /usr/lib/systemd/system/docker.service file and add -Htcp://0.0.0.0:12375 -H unix://var/run/docker.sock as shown below:

Save the file and reload the configuration and restart

systemctl daemon-reload # Reload configuration systemctl restart docker.service # Restart docker service

Note: -Htcp://0.0.0.0:12375 means that any IP address can use TCP to access this port. You can match the IP address based on the actual situation. Because there is no token or key here, please pay special attention. If you use a cloud server, it is strongly recommended to set it to security group IP whitelist access. I was attacked within three or four hours of using Docker to publish in a test environment. However, I used port 2375, which is particularly vulnerable to attacks.

Configure IDEAdocker environment

The idea installation docker environment plug-in is as follows:

After the installation is complete, restart idea and open the springboot project, and create a Dockerfile file in the root directory. As shown below:

Edit the Dockerfile as follows:

FROM openjdk:11
# The image is inherited from openjdk:11-jdk-alpin VOLUME /root/tmp
# Indicates that the /root/tmp directory is mounted into the container ADD build/libs/brief-plus-0.0.1-SNAPSHOT.jar apprun.jar
# Add bootJar to the image. The command in the root directory is apprun.jar
 
ENTRYPOINT ["java","-jar","/apprun.jar"]
#ENTRYPOINT Execute the java command to run the program after the container is started # Set the container time ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# ======= Some other Dockerfile commands ========== We don't use them here but we'll mention them anyway #COPY package.json /usr/src/app/
#ADD More advanced copy file #ADD instruction and COPY format and nature are basically the same. But some functions are added based on COPY.
The #CMD instruction is used to specify the default startup command of the container main process.
#ENV sets environment variables #HEALTHCHECK health check #EXPOSE The instruction declares the service port provided by the runtime container. This is just a declaration. The application will not open the service of this port at runtime because of this declaration EXPOSE 8090

Pay special attention to the sentence build/libs/brief-plus-0.0.1-SNAPSHOT.jar apprun.jar. The files compiled by gradle are located in the build/libs/ directory as shown below:

The files compiled by Maven are located in the target directory as shown below:

Dockerfile generates the image file based on the specific directory and packaged name, so there must be no mistakes here.

Configure Docker Service

Configure the operating environment

Create a tcp connection service

3. Configure services published to Docker

Detailed configuration of binding port ip

Package Release

Tips

1. The docker image file will be divided into blocks, each with its own signature. Each time it is uploaded, the difference will be compared and the files will be uploaded again.

2. Remember to change the tag every time you upload so that you can roll back based on the tag.

3. Modifying the server's network configuration and firewall requires restarting the Docker service.

Common docker commands:

Restart Docker

systemctl restart docker # Restart the docker service systemctl daemon-reload # Reload the docker configuration

View logs within 30 minutes

docker logs --since 30m id

The above is the detailed content of the actual record of Centos8.3 and docker deployment of springboot project. For more information about docker deployment of springboot project, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed steps to deploy SpringBoot projects using Docker in Idea
  • How to deploy SpringBoot project using Docker
  • How to deploy SpringBoot project using Dockerfile
  • The solution for the Springboot project to build a war package docker package and not find static resources under resource
  • Detailed explanation of the docker deployment practice of the springboot project

<<:  Summary of common MySQL table design errors

>>:  Three common style selectors in html css

Recommend

Vue imports Echarts to realize line scatter chart

This article shares the specific code of Vue impo...

Linux firewall iptables detailed introduction, configuration method and case

1.1 Introduction to iptables firewall Netfilter/I...

Detailed explanation of MySQL database paradigm

Preface: I have often heard about database paradi...

Detailed explanation of three ways to cut catalina.out logs in tomcat

1. Log4j for log segmentation 1) Prepare three pa...

MySQL 8.0.11 installation and configuration method graphic tutorial

The installation and configuration methods of MyS...

Summary of methods for querying MySQL user permissions

Introduce two methods to view MySQL user permissi...

MySQL statement execution order and writing order example analysis

The complete syntax of the select statement is: S...

How to install OpenSuse on virtualbox

The virtual machine is installed on the host mach...

Detailed explanation of Nginx rewrite jump application scenarios

Application scenario 1: Domain name-based redirec...

Summary of Common Letters in Unicode

Most of the earliest computers could only use ASC...

Detailed explanation of the role of brackets in AngularJS

1. The role of brackets 1.1 Square brackets [ ] W...

JavaScript dynamically generates a table with row deletion function

This article example shares the specific code of ...

Solve the problem of MySql client exiting in seconds (my.ini not found)

Problem description (environment: windows7, MySql...

HTML sample code for implementing tab switching

Tab switching is also a common technology in proj...

JavaScript implements div mouse drag effect

This article shares the specific code for JavaScr...