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 and publish online projects in Docker

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to deploy and release online projects in Docker". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to deploy and release online projects in Docker".

Step 1: package the project

Because springboot projects are packaged into jar packages by default, as well as their own tomcat containers, the packaging method is modified first.

01: modify the packaging method in pom.xml war02: cancel the tomcat container org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat that comes with springboot 03: configure plug-in

Otherwise, you will be prompted that the web.xml file is missing

Org.apache.maven.plugins maven-war-plugin 2.6false 04: modify the startup class of springboot

Create a SpringBootStartApplication.class in the sibling directory of the startup class

Package com.hui.myblog;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;/** * @ author www.huiblog.top * @ date 19:22 on 2020-9-24 * QQ:2473181454 * Summary: * / public class SpringBootStartApplication extends SpringBootServletInitializer {@ Override protected SpringApplicationBuilder configure (SpringApplicationBuilder builder) {/ / Note here to point to the Application startup class return builder.sources (MyblogApplication.class) that was originally executed with the main method. }} 05: packaged

If the project of IDEA is selected directly, maven-clean-package on the right can be selected.

After the package is successful, a project for the war package is generated in the target directory.

Step 2: deploy

Equipment required for deployment:

Remote linux host (here the blogger bought Ali's ecs server)

Have some basic knowledge of linux (just a few simple commands, such as mkdir, etc.)

A domain name that has been filed.

If all of the above are available, then let's start with the next deployment.

Images involved in installing your own project in 01:Docker

Here, the blogger only uses tomcat,mysql,nginx.

Download the image, configure the image, start the container, and the blogger won't talk nonsense here.

No, you can read this article: Docker is easy to use

Record the steps of configuring tomcat image here, because the blogger has encountered a big pit.

① pulls the image:

Here the blogger chose tomcat7.0.

Docker pull tomcat:7.0 ② boot image container: docker run-it-p 8888 purl 8080-v / myproject/myblog:/webapps-v / myproject/myblog/tomcatlog:/logs tomcat:7.0 / bin/bash

Instruction interpretation:

-it: run as a daemon

-p: note that here is lowercase p, and uppercase P will randomly assign the port number. Here, port 8080 inside the container is mapped to external port 8888, and port 8888 is placed outside.

-v: set to hang in the directory

Atomcat myproject/myblog:/webapps sets up the projects under native myblog and the files under webapps in the tomcat container to mount

The log under the native tomcatlog and the log under the logs in the tomcat container are mounted on BRV / myproject/myblog/tomcatlog:/logs.

OK, at this point, the operation in docker is over, and then the project is released.

02: transfer your project to the remote host

You can choose to use finallshell or xftp here.

Bloggers use finallshell, go directly to the previously set directory / myproject/myblog, and put their own war package project.

Note: there is no need to decompress yourself here. The tomcat container will automatically extract its own war package project.

After the project is put away, you can restart the tomcat container, which will access the project directly through the public network ip: Port number / project name.

Step 3: configure nginx reverse proxy

After the project is deployed, it can only be accessed through the public network ip: Port / project name, but most online projects are accessed using domain names. Here, you need to set the reverse proxy of nginx.

At the beginning, the blogger downloaded the nginx image in the docker container, which was configured for a long time, but it was not successful. Then there was a test of downloading a nginx through yum in the remote host, but in the end, it was unsuccessful. At this point, I almost wanted to give up and deploy directly through the jar package. However, there is no harm in learning a little more, and we can solve it later.

So, finally, download a nginx package directly from the server, install it yourself, and finally succeed. The detailed steps are as follows

01: download the compressed package

When the blogger himself learned before, there was a nginx package on the computer, which was passed directly to the server.

02: extract nginxtar-xvf package name 03: download nginx dependent yum-y install make zlib zlib-devel gcc-c++libtool openssl openssl-devel04: install

First go to your extracted nginx directory and enter the following instructions

. / configure

After the execution, there is no error to prove that everything is normal, and then enter

Make & & make install

All right, nginx installation is over.

05: start the nginx service

After the nginx installation is successful, install the directory again / usr/local/nginx

Enter the directory:

# start nginx service cd / usr/local/nginx/sbin/nginx

After the service is started, you can access it through the public network ip:80. If an error page of nginx appears and proves that everything is normal and does not appear, the solution is as follows:

Open the security group port 80 of the esc server

Turn off the server's firewall

The firewall directives are as follows:

View firewall service status

Systemctl status firewalld

An active:active (running) highlight indicates that it is in a startup state

The appearance of active:inactive (dead) gray indicates stop, and it is OK to look at the word here.

View firewall status

Firewall-cmd-state

Enable, restart, and shut down firewalld services

Enable: service firewalld start

Turn off: service firewalld stop

Restart: service firewalld restart

View firewall rules

Firewall-cmd-list-all

Query, open, close port

Query: firewall-cmd-query-port=8080/tcp

Open: firewall-cmd-permanent-add-port=80/tcp

Remove: firewall-cmd-permanent-remove-port=8080/tcp

Restart the firewall (you need to restart the firewall after changing the configuration): firewall-cmd-reload

Parameter interpretation

1. Firwall-cmd: a tool for operating firewall provided by Linux

2.-permanent: set to persistent

There should be no problem with access after the firewall is turned off. if you still can't access it, you can leave a message in the comment area, or contact the blogger to study it.

06: configure nginx reverse proxy (key, Tai Keng)

First go to your own nginx configuration file directory. If your installation method is the same as mine, the path should be the same.

Cd / usr/local/nginx/conf

After entering, you can see that there is a nginx.conf file

The view method of upstream tdl {server here will be indicated below: 8080 [remember not to write / project name];} server {listen 80; server_name public network ip; location / {proxy_pass http://tdl;}}

The address of server in tdl is the address of the tomcat container that has been launched in your docker container. What bloggers understand here is that each container is equivalent to a small independent centos virtual machine. Don't think that this project can be accessed through the public network ip: Port number / project name. Just write it like this, don't remember. View it as follows:

Enter the tomcat container that has been started

Docker exec-it container id / bin/bash

Check the host address of your current container

Cd / etc/hosts

After typing, there will be an address beginning with 172 at the bottom.

Exit the container:

Ctrl + p + Q

Configure the tomcat root directory to access the project directly:

The simplest:

Delete the ROOT file under webapp and change your project name to ROOT

Clean the computer's dns cache

Cmd runs ipconfig / flushdns

OK, so far, the project has been deployed, and now you can access your project directly through the domain name. During the re-deployment process, there is really a huge pit, network environment, cache, and all kinds of problems. However, in the end, the project started to run. I also learned a lot of knowledge, and I was very happy in the end.

Here, there are still many problems with this deployment. Nginx is still not in the docker container. Docker needs to start three containers at a time.

Thank you for your reading, the above is the content of "how to deploy and release online projects in Docker". After the study of this article, I believe you have a deeper understanding of how to deploy and release online projects in Docker, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Servers

Wechat

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

12
Report