Tutorial on deploying springboot package in linux environment using docker

Tutorial on deploying springboot package in linux environment using docker

Because springboot has a built-in tomcat server, it can be run directly after being packaged into a jar package.

First, let's look at the packaging deployment in the Windows environment

1. Install and package

2. Check whether the project jar package exists in the target directory

insert image description here

3. If the project jar package already exists, you can run it directly (as mentioned earlier, the springboot package can be run directly)

insert image description here

4. Use the java -jar command in the dos command box

java -jar springboot-nriat-common-demo-0.0.1-SNAPSHOT.jar 

insert image description here

Startup effect:

insert image description here

insert image description here

No error, startup successful!

The above is about the springboot package deployment on the windows system. Let's get to the point.

Use docker to deploy packages in linux system.

1. First, you need to prepare a dockerfile file, the content of the file is as follows:

# Specify the base image FROM java:8
# Maintainer information MAINTAINER lbl
# Define anonymous volume VOLUME /tmp
#Copy the file or change the name ADD springboot-nriat-common-demo-0.0.1-SNAPSHOT.jar app.jar
# Allow the specified port EXPOSE 8087
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

File parsing

insert image description here

Explain this configuration file:

VOLUME specifies the temporary file directory as /tmp. The effect is that a temporary file is created in the host's /var/lib/docker directory and linked to the container's /tmp. This step is optional, but necessary if the application involves a file system. The /tmp directory is used to persist to the Docker data folder, because the embedded Tomcat container used by Spring Boot uses /tmp as the working directory by default. The project's jar file is added to the container as "app.jar"
ENTRYPOINT Execute project app.jar. To shorten Tomcat startup time, add a system property pointing to "/dev/./urandom" as Entropy Source

If it is the first time to package, it will automatically download the Java 8 image as the base image, and will not download it again when making images in the future.

2. Put the dockerfile file and the jar package of the springboot project in the same folder

insert image description here

3. Then start making the image

docker build -t springboot-docker .

Use docker images to check whether the image has been generated

docker images

insert image description here

5. Configure the springboot project and start the container

docker run -d -p 8087:8087 8493c1f0592c

The -d parameter allows the container to run in the background
-p is for port mapping. In this case, port 8080 in the server is mapped to port 8087 in the container (the port configured in the project is 8087). The port uses the IMAGE ID of the images image.

6. Finally, use docker ps -a to check whether it has been started.

docker ps -a 

insert image description here

Startup successful! !

This is the end of this article about using docker to deploy springboot packages in a linux environment. For more information about docker deploying springboot packages, 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:
  • Springboot multi-module multi-environment configuration file problem (dynamic configuration of production and development environment)
  • Detailed steps for building an SSM development environment based on SpringBoot in IntelliJ IDEA
  • SpringBoot environment configuration knowledge summary
  • Use tomcat to deploy SpringBoot war package in centos environment
  • Clever use of profiles in springboot yml (multi-environment configuration for beginners)
  • Detailed explanation of SpringBoot+docker environment variable configuration
  • Detailed tutorial on building a springboot selenium web page file to image environment
  • Springboot multi-environment switching method
  • SpringBoot environment construction and first program running (novice tutorial)
  • Matplotlib visualization custom colors to draw beautiful statistical graphs

<<:  CSS3 changes the browser scroll bar style

>>:  Vue imports Echarts to realize line scatter chart

Recommend

How to install openssh from source code in centos 7

Environment: CentOS 7.1.1503 Minimum Installation...

Detailed explanation of Nginx version smooth upgrade solution

Table of contents background: Nginx smooth upgrad...

Complete example of vue polling request solution

Understanding of polling In fact, the focus of po...

How to install ElasticSearch on Docker in one article

Table of contents Preface 1. Install Docker 2. In...

Analysis of different MySQL table sorting rules error

The following error is reported when MySQL joins ...

js to realize web message board function

This article example shares the specific code of ...

The difference and usage between div and span

Table of contents 1. Differences and characterist...

Linux Check the installation location of the software simple method

1. Check the software installation path: There is...

Notes on using $refs in Vue instances

During the development process, we often use the ...

The leftmost matching principle of MySQL database index

Table of contents 1. Joint index description 2. C...

How to optimize a website to increase access speed update

Recently, the company has begun to evaluate all s...

Detailed explanation of mysql download and installation process

1: Download MySql Official website download addre...

VUE implements a Flappy Bird game sample code

Flappy Bird is a very simple little game that eve...

Detailed explanation of Vue3 sandbox mechanism

Table of contents Preface Browser compiled versio...

Two ways to write stored procedures in Mysql with and without return values

Process 1: with return value: drop procedure if e...