How to deploy the springboot project in the IDE (swagger and no swagger are the same) to the docker on the server or virtual machine

I. Introduction

I recently wrote a project, but the front-end has not been written yet, and I need to deploy it to the server to implement the front-end for my girlfriend, but I am not familiar with Linux, I tiptoe, every step is really a bug, it can be said that every step is difficult, and I am desperate for the world , I once suspected that there was a problem with my server, and I even suspected that there was a problem with my DaoBan IDE. After two days and one night, I finally...deployed it.

2. Now start to share the installation process:

1. Buy a server or install a virtual machine (kinda like crap)

2. Install docker (you can use yum to install)

Tips: After installing docker, you need to configure it. Enter the following line of code to enter the docker configuration file, add configuration after ExecStart=, and the port for remote access to docker is 2375. sos: If it is a server, you need to configure it on the server after
modification Check the port number, otherwise the ide will not recognize the port number, which is very important (this pit has been stepped on for a long time, and it is about to fall into it)

​​​​insert image description here

1.vim /lib/systemd/system/docker.service  #输入,进到这个配置文件
2.-H tcp://0.0.0.0:2375                   #复制粘贴这个
3.退出编辑界面:先按esc,然后":wq"退出
4.# 重启docker
systemctl daemon-reload
systemctl restart docker

3. At the third step, it means that we have configured the docker, and now we need to pull the MySQL image in the docker

1.docker pull mysql:8.0(本人用8.0,需要什么版本号在后面改就好)
2.docker run -itd --name mysql -p 3306:3306-e MYSQL_ROOT_PASSWORD=root mysql:8.0

Tips: There is also a pitfall in this step. If you have installed mysql locally before installing docker, and the port number is also 3306, you must keep it closed, otherwise it will cause port number conflicts, and windows navigate or little dolphin will Can't connect to the mysql of the virtual machine

4. At this point, the work of the virtual machine is finished. Go back to the ide, first modify the connection address of mysql in the yml file, the ip and port number need to be changed to the virtual machine, and the password should also be changed.
Secondly, you need to add the docker-maven-plugin plugin to the pom file

<!-- docker-maven-plugin-->
	<plugin>
		<groupId>com.spotify</groupId>
			<artifactId>docker-maven-plugin</artifactId>
			<version>1.2.2</version>
			<configuration>
				<!-- Docker路径 -->
				<dockerHost>http://虚拟机的ip:2375(刚开始设置的docker端口号)</dockerHost>
				<!-- Dockerfile定义 -->
				<baseImage>openjdk:11</baseImage>
<!-- 作者 -->
				<maintainer>jackie</maintainer>
				<resources>
					<resource>
						<!-- 复制jar包到docker容器指定目录 -->
						<targetPath>/</targetPath>
	<!-- 从哪个包拷贝文件,target包 -->
					    <directory>${project.build.directory}</directory>
    <!-- 拷贝哪个文件 -->
						<include>${project.build.finalName}.jar</include>
					</resource>
				</resources>
				<workdir>/</workdir>
				<entryPoint>
                   ["java", "-jar", "${project.build.finalName}.jar"]
                </entryPoint>
				<forceTags>true</forceTags>
	<!-- 镜像名 -->
				<imageName>${project.artifactId}</imageName>
	<!-- 镜像版本 -->
				<imageTags>
					<imageTag>${project.version}</imageTag>
				</imageTags>
			</configuration>
	 </plugin>

5. Packing, order.
insert image description here
6. At this point, the docker plug-in has been loaded. Open the plug-in and click build. If BUID SUCESS is displayed at the end of the run, it means that the package has been successfully transferred to the virtual machine. Check it in the virtual machine (if it fails here, the probability is The port number 2375 is not released on the server)
insert image description here
7. Go back to the virtual machine and enter the command

docker images

If you see
insert image description here
it is successful, now to run this project input

docker run -d -p 80:80 项目名:0.0.1-SNAPSHOT

insert image description here
-d is running in the background, -p: binding port number, the first 80 is the port exposed to the outside world (customized) when starting the image, and the second 80 is the port of the downloaded image (original project port).

Next, check whether your project is successful, enter the command, and your project name will appear, and then you can view the project in a local browser.

docker ps

This is the painful process this time. This kind of thing is really annoying. It requires patience and careful operation step by step. I hope it can help you. If you don’t mind, you can give it a thumbs up.

Guess you like

Origin blog.csdn.net/m0_58847451/article/details/128581369