Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy SpringBoot Project quickly by Docker

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to deploy the SpringBoot project quickly by Docker". In the daily operation, I believe many people have doubts about how to deploy the SpringBoot project quickly by Docker. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to deploy the SpringBoot project quickly by Docker". Next, please follow the editor to study!

1. Install Docker

First open the linux environment and enter the following command to install:

Install yum install docker to check whether docker is installed successfully-- version# starts systemctl start docker

If the download is slow, you can switch to the domestic Aliyun image to download:

Change the image source sudo vim / etc/docker/daemon.json as follows: {"registry-mirrors": ["https://m9r2r2uj.mirror.aliyuncs.com"]} save exit, restart docker:systemctl restart docker2, install Redis

First, search for redis in DockerHub. After clicking to enter the details page, you can see how to use below. If you need to select a specific version, there is Supported tags for us to choose. Then, if you pull the latest version, pull the following command tutorial as follows:

Pull the redis image docker pull redis to view the local redis image docker images run redisdocker run-- name myredis-p 6379 docker images-- d redis redis-server-- appendonly yes

Docker run means to run.

-name myredis means it's called myredis.

-p 6379 6379 means to map 6379 of the server to port 6379 of docker, so that the port of docker can be accessed through the port of the server.

-d means to run redis redis redis-server as a backend service-- appendonly yes means to enable persistent cache mode, which can be saved to hard disk.

3. Install MySQL drop-down MySQL image: docker pull mysql:5.7.27Docker run MySQL:docker run-- name mymysql-e MYSQL_ROOT_PASSWORD=admin-d-p 3306 docker pull mysql:5.7.27Docker 3306 mysql:5.7.274, install RabbitMQ

One line of command is done. Note that RABBITMQ_DEFAULT_PASS=password means to set a password. Operations such as drop-down images have been secretly done in this command:

Docker run-d-- hostname my-rabbit-- name myrabbit-e RABBITMQ_DEFAULT_USER=root-e RABBITMQ_DEFAULT_PASS=admin-p 15672 RABBITMQ_DEFAULT_USER=root 15672 rabbitmq:management5, install ElasticSearch

Drop-down mirror operation is omitted:

Start: docker run-p 9200 name es_643 elasticsearch:6.4.3 9300-d-- enter the image: docker exec-it es_643 / bin/bash install the Chinese word segmentation plug-in:. / bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.3/elasticsearch-analysis-ik-6.4.3.zip exit and restart the image exitdocker restart es_6436, build the Docker image of the project

We use the command to pull the project on the github:

Drop-down project (eblog): clone https://github.com/MarkerHub/eblog.git enter folder: cd eblog package: mvn clean package-Dmaven.test.skip=true

Upload the typed jar package to the linux server!

Next, write DockerFile, which can build our packaged jar package code into an image:

FROM java:8EXPOSE 8080VOLUME / tmpENV TZ=Asia/ShanghaiRUN ln-sf / usr/share/zoneinfo/ {TZ} / etc/localtime & & echo "{TZ}" > / etc/timezoneADD eblog-0.0.1-SNAPSHOT.jar / app.jarRUN bash-c 'touch / app.jar'ENTRYPOINT ["java", "- jar", "/ app.jar"]

FROM java:8 is based on jdk8 environment.

EXPOSE 8080 indicates that the exposed port is 8080

VOLUME / tmp means mounting to the / tmp directory

ADD eblog-0.0.1-SNAPSHOT.jar / app.jar means to copy the jar package to the root directory in the mirror service and rename it app.jar

RUN bash-c 'touch / app.jar' means to create an app.jar

ENTRYPOINT ["java", "- jar", "/ app.jar"] means to execute the startup command java-jar

Next, we install Dockrfile, and then use DockerFile to build eblog-0.0.1-SNAPSHOT.jar into an image:

Construct the image docker build-t eblog. View image docker images

After this step is completed, we can finish the preparatory work, and then we will start our project directly.

7. Run the project image to complete the project startup

The command is as follows:

Docker run-p 8080 link myrabbit:erabbit 8080-p 9326 link myrabbit:erabbit-name eblog-- link es_643:ees-- link mymysql:emysql-- link myredis:eredis-d eblog

-p 8080 es 8080-p 9326 es 9326: 9326 is due to the port needed for live chat-link es:ees represents the associated container and the container is nicknamed ees

View the eblog print log:

Docker logs-f eblog

This project runs successfully!

Note: it is easier to use DockerCompose

At this point, the study on "how to quickly deploy the SpringBoot project by Docker" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report