Detailed steps for running springboot project in Linux Docker

Detailed steps for running springboot project in Linux Docker

Introduction:

The configuration of Docker running the springboot project is actually very simple, which is exactly the same as running springboot directly on Linux. start

1: We first need a running Docker environment

Step 1: Install using yum (under CentOS 7)

Docker requires the CentOS kernel version to be higher than 3.10. Check the prerequisites on this page to verify whether your CentOS version supports Docker.

Use the uname -r command to check your current kernel version

[root@iZbp1gp1t778obaz5m8vk8Z ~]# uname -r
3.10.0-957.21.3.el7.x86_64

Step 2: Install Docker

The Docker package and its dependencies are already included in the default CentOS-Extras software source. The installation command is as follows:

[root@iZbp1gp1t778obaz5m8vk8Z ~]# yum -y install docker

The installation is complete.

Step 3: Start the Docker background service

[root@iZbp1gp1t778obaz5m8vk8Z ~]# service docker start

Step 4: Test and run hello-world

[root@izwz99z5o9dc90keftqhlrz ~]# docker run hello-world
 
Hello from Docker!
This message shows that your installation appears to be working correctly.
 
To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  (amd64)
 3. The Docker daemon creates a new container from that image which runs the
  executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
  to your terminal.
 
To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
 
Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/
 
For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Since there is no hello-world image locally, a hello-world image will be downloaded and run in the container. Now let's start using it for real.

2: Let's start with our own docker springboot configuration

Step 1: Create an operation account to run Docker. Newly added - not related to the following document content [ operation is generally not allowed to be done by root ]

[root@iZbp1gp1t778obaz5m8vk8Z ~]# useradd -d /home/hn-docker -m hn-docker #Create an operation account [root@iZbp1gp1t778obaz5m8vk8Z ~]# 
[root@iZbp1gp1t778obaz5m8vk8Z ~]# passwd hn-docker #Change password Changing password for user hn-docker.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@iZbp1gp1t778obaz5m8vk8Z ~]# sudo groupadd docker #Add docker user group. If it already exists, it is not needed. [root@iZbp1gp1t778obaz5m8vk8Z ~]# sudo gpasswd -a hn-docker docker ##Add the logged in user to the docker user group Adding user hn-docker to group docker

Step 2: Start Docker operation and maintenance

[root@izwz99z5o9dc90keftqhlrz Docker]# pwd
/root/Docker
[root@izwz99z5o9dc90keftqhlrz Docker]# 
[root@izwz99z5o9dc90keftqhlrz Docker]# 
[root@izwz99z5o9dc90keftqhlrz Docker]# mkdir elasticsearch
[root@izwz99z5o9dc90keftqhlrz Docker]# 
[root@izwz99z5o9dc90keftqhlrz Docker]# cd elasticsearch/
[root@izwz99z5o9dc90keftqhlrz elasticsearch]#

1. Run mvn install to package the project into a jar package
2. Copy the jar package to the currently created folder and the Dockerfile file to a folder

[root@izwz99z5o9dc90keftqhlrz elasticsearch]# touch Dockerfile 
[root@izwz99z5o9dc90keftqhlrz elasticsearch]# vi Dockerfile 
 
# The base image uses java
FROM java:8
# MAINTAINER shixiong <[email protected]>
# VOLUME specifies the temporary file directory as /tmp.
# The effect is to create a temporary file in the host's /var/lib/docker directory and link it to the container's /tmp
VOLUME /tmp
# Add the jar package to the container and rename it to app.jar. You can use relative paths or absolute paths. Here, the relative path is ADD springboot-es6.jar /springboot-es6.jar
# Run the jar package RUN bash -c 'touch /springboot-es6.jar'
#Set the time zone - otherwise it will be 8 hours slower than the current time RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/springboot-es6.jar"]

3: Build our springboot project to Docker and generate a docker image

3. Enter the folder and run the command. The results will be different when running with or without the version. ! !

[root@izwz99z5o9dc90keftqhlrz elasticsearch]# docker build -t springboot-es6:v1.0 .
The above configuration: The runtime command is:
[root@izwz99z5o9dc90keftqhlrz elasticsearch]# docker run -d -p 8099:8099 springboot-es6:v1.0
 
[root@izwz99z5o9dc90keftqhlrz elasticsearch]# docker build -t springboot-es6 .
The above configuration: The runtime command is:
[root@izwz99z5o9dc90keftqhlrz elasticsearch]# docker run -d -p 8099:8099 springboot-es6 

With the image generated by v1.0, the wrong command is like this:

4: Run the springboot project in Docker

[root@izwz99z5o9dc90keftqhlrz elasticsearch]# docker run -d -p 8099:8099 springboot-es6
e7a56662f804ef72e7dcae3fa71e840c35e28e18aa1aff7e98b71d900b17c305
[root@izwz99z5o9dc90keftqhlrz elasticsearch]#

Five: See if our interface can be used

The interface is perfectly used, and the following describes how to manage containers and view logs.

This is the end of this article about Linux Docker running springboot project. For more relevant Docker running springboot project content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

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

<<:  Example code for implementing bottom alignment in multiple ways with CSS

>>:  WeChat Mini Program QR Code Generation Tool weapp-qrcode Detailed Explanation

Recommend

How to use JavaScript to implement sorting algorithms

Table of contents Bubble Sort Selection Sort Inse...

Analysis of the causes of accidents caused by Unicode signature BOM

Maybe you are using include files here, which is u...

Analysis of Facebook's Information Architecture

<br />Original: http://uicom.net/blog/?p=762...

Example of using Nginx reverse proxy to go-fastdfs

background go-fastdfs is a distributed file syste...

Tips on setting HTML table borders

For many people who are new to HTML, table <ta...

How to set mysql5.7 encoding set to utf8mb4

I recently encountered a problem. The emoticons o...

How to use squid to build a proxy server for http and https

When we introduced nginx, we also used nginx to s...

MySQL 5.7.17 installation and configuration tutorial for Mac

1. Download MySQL Click on the official website d...

Detailed explanation of Javascript basics

Table of contents variable Data Types Extension P...

mysql zip file installation tutorial

This article shares the specific method of instal...

Deleting two images with the same id in docker

When I created a Docker container today, I accide...

The "3I" Standards for Successful Print Advertising

For many domestic advertisers, the creation and ev...

Learn MySQL index pushdown in five minutes

Table of contents Preface What is index pushdown?...