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

Example code for implementing ellipse trajectory rotation using CSS3

Recently, the following effects need to be achiev...

Various ways to modify the background image color using CSS3

CSS3 can change the color of pictures. From now o...

Pure HTML+CSS to achieve typing effect

This article mainly introduces the typing effect ...

Basic usage of @Font-face and how to make it compatible with all browsers

@Font-face basic introduction: @font-face is a CSS...

Tutorial on how to install and use Ceph distributed software under Linux

Table of contents Preface 1. Basic Environment 1....

Solving problems encountered when importing and exporting Mysql

background Since I converted all my tasks to Dock...

JavaScript regular verification password strength implementation method

exhibit design Password strength analysis The pas...

Detailed explanation of linux crm deployment code

Linux basic configuration Compile and install pyt...

Linux nohup to run programs in the background and view them (nohup and &)

1. Background execution Generally, programs on Li...

Implementation steps for docker deployment lnmp-wordpress

Table of contents 1. Experimental Environment 2. ...

MySQL 5.7.18 installation and configuration method graphic tutorial (CentOS7)

How to install MySQL 5.7.18 on Linux 1. Download ...