Analyzing the practical record of using docker to build microservices with SpringBoot

Analyzing the practical record of using docker to build microservices with SpringBoot

What is it?

Spring Boot is a sub-project of the Spring open source organization and a one-stop solution for Spring components. It simplifies the difficulty of using Spring, saves the heavy configuration, and provides various starters so that developers can get started quickly.


Why use it?

Five advantages:

1. Starting Dependencies The official has integrated a large number of starting dependencies for us, which simplifies our work of building projects. At the same time, starting dependencies provide reliable dependency management, reducing the risk of introducing problematic versions and dependency conflicts into the project.

2. Automatic configuration turns on component scanning and automatic configuration. Disable specific auto-configuration via the exclude parameter.

3. Application monitoring The core of Spring Boot monitoring is the spring-boot-starter-actuator dependency. After adding the dependency, Spring Boot will configure some common monitoring by default, such as jvm monitoring, class loading, health monitoring, etc. The Actuator plug-in is a service provided by SpringBoot natively. It can be used to output a lot of endpoint information in the application by exposing endpoint routing.

4. Independent operation SpringBoot has a built-in Tomcat container, and you can directly execute the main method to run. The project deployment can be packaged into a jar file and run the service on the server by executing the java -jar command.

5. During the development of a hot deployment project, page data or data structure is often changed. In order to display the effect of the change, it is often necessary to restart the application to view the change effect. In fact, it is to recompile and generate a new Class file. This file records various information corresponding to the code, and then the Class file will be loaded by the virtual machine's ClassLoader.

Hot deployment takes advantage of this feature. If it detects that a Class file has been changed, it will create a new ClassLoader to load the file. After a series of processes, the result will be presented to us.


Case

1. Develop springboot microservices

2. Package the springboot application

There are generally two formats of packages, the case uses jar
war transition tomcat
jar mainstream jdk

3. Package the project

aliyun-sdk-oss-2.6.1.jar

4. Create a Dockerfile directory in the server

mkdir /root/springboot

Upload the jar package to this directory and load the Java environment image openjdk /root/springboot

insert image description here

Create a Dockerfile
vim Dockerfile

FROM openjdk:8-jre
WORKDIR /app
ADD aliyun-sdk-oss-2.6.1.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]

5. Build the image
docker build -t app1 .

insert image description here

6. Run the container
docker run -d -p 8081:8080 --name registry1 app1 bash
View the container:

insert image description here


This is the end of this article about analyzing the practical records of using docker and SpringBoot to build microservices. For more relevant content about building microservices with docker and SpringBoot, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Analysis of Springboot microservice packaging Docker image process
  • SpringBoot+SpringCloud user information microservice delivery implementation analysis
  • SpringBoot integrated gRPC microservice engineering construction practice method

<<:  HTML adaptive table method

>>:  9 Tips for MySQL Database Optimization

Recommend

How to use cutecom for serial communication in Ubuntu virtual machine

Using cutecom for serial communication in Ubuntu ...

CSS3 clear float method example

1. Purpose Through this article, everyone can und...

Summary of Linux Logical Volume Management (LVM) usage

Managing disk space is an important daily task fo...

How to use VIM editor in Linux

As a powerful editor with rich options, Vim is lo...

Basic installation tutorial of mysql decompression package

Since I have changed to a new computer, all the e...

Markup Languages ​​- What to learn after learning HTML?

Click here to return to the 123WORDPRESS.COM HTML ...

Install mysql5.7 on Ubuntu 18.04

Ubuntu 18.04 installs mysql 5.7 for your referenc...

CSS3 implements the sample code of NES game console

Achieve resultsImplementation Code html <input...

Vue advanced usage tutorial dynamic components

Table of contents Basic description AST parsing R...

Implementation of building custom images with Dockerfile

Table of contents Preface Introduction to Dockerf...

Zookeeper stand-alone environment and cluster environment construction

1. Single machine environment construction# 1.1 D...

Implementation of Single Div drawing techniques in CSS

You can often see articles about CSS drawing, suc...