IDEA SpringBoot aggregate project jar package, docker deployment


1. Front

  1. The above blog has written a way to build the project, and some introduced Portal : https: //blog.csdn.net/qq_38637558/article/details/105167120
  2. I use Windows, this is actually no difference.
  3. The development tool is IntelliJ IDEA
  4. Will introduce two ways to upload to the server

2. IDEA configuration

Insert picture description here
Successful is the link success. If
my Windows is the column, you need to turn on this:
Insert picture description here
Project structure:
Insert picture description here
Dockerfile file content:

#  基础镜像必要,代表你的项目将构建在这个基础上面
FROM java:8
# 对外端口
EXPOSE 8088
# 创建一个可以从本地主机或其他容器挂载的挂载点,一般用来存放数据库和需要保持的数据等
# VOLUME 指定了临时文件目录为/tmp。
# 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp
VOLUME /tmp
# 将jar包添加到容器中并更名为 testDemo.jar.我们在base(项目入口)的pom.xml中指定了打包后的jar名
COPY base/target/testDemo.jar testDemo.jar
# 运行jar包
RUN bash -c 'touch /testDemo.jar'
# 指定容器启动程序及参数
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/testDemo.jar"]

Insert picture description here
Insert picture description here

3. Package the jar file

First select the environment. As mentioned earlier, we can
Insert picture description here
clenan the package first. At
Insert picture description here
this time, we can run the jar file first to see if there is any problem with the packaged file. Next step:
Insert picture description here

4. Upload to the server via local docker

1. Package the image to the local

Insert picture description here

Insert picture description here

Insert picture description here

Run the mirror to see if there are any problems;
Insert picture description here
OK, at this step, our mirror has been packaged, and the rest will be transferred to our server, and nothing can be run on this machine.
Two methods:

  1. Through the private docker library:, portal : https://blog.csdn.net/qq_38637558/article/details/99603071
  2. Transfer through the official docker, docker hub, it seems to be this, you can set the project to be private, it is recommended not to use this method
  3. That's what I'm going to introduce next

2. Upload the image to the server

Package the local image first

docker save -o testdemo.tar testdemo:1.0  

Insert picture description here
Upload to server

Unzip the file to the image:

docker load < testdemo.tar

Insert picture description here



5. Package the image directly to the server (recommended)

1. Configure this place as the address of the server

Insert picture description here

2. Configure the docker of the server

文件地址:
vim /usr/lib/systemd/system/docker.service

所加参数:
-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

systemctl daemon-reload // 1,加载docker守护线程
systemctl restart docker // 2,重启docker

Open port 2375, be sure to close it, because this port, as long as I know your server IP address, I can connect to the docker service, and then pull to your mirror...firewall, security group, designated IP, certificate can be handled, this place must pay attention to
Insert picture description here
areas requiring attention are: this place must confirm format, or wrong, the restart will fail, do not uninstall then reinstall, you want to believe they can be solved
will be reported this error:

Failed to restart docker.service: Unit is not loaded properly: Invalid argument. See system logs and 'systemctl status docker.service' for details.

Insert picture description here

3. Run the dockerfile file: Build Image

Insert picture description here

4. Go to the server to view

docker images

6, miscellaneous talk

  1. I also found a tutorial on the Internet, and then I figured it out. If it is difficult, it feels very simple if you know it, but if you haven't done it, it may be a little bit difficult, a little bit

  2. Configure docker container environment variablesENV JAVA_OPTS=""

  3. It feels like there is nothing to comment on, it's all very simple

  4. 1. Maven Profiles select the environment, check one
    2. Maven testdemo(root) --> clean --> package
    3. Modify the docker configuration file Run/Debug Configurations, modify the version number Image tag (note the version number for each update Modify it to distinguish)
    4. The arrow in the Dockerfile file, build image
    5. View the mirror docker images
    6. Run the local test again
    7. docker save -o testdemo.tar testdemo:1.0
    8. Upload to the server
    9. docker load < testdemo.tar
    10. docker run -p 8080:8080 --name testdemo–restart=always -d testdemo:1.0 (-v log mount, pictures and other files are mounted)
    11. Check the startup log, confirm the startup status, and configure Environment, the first few lines of the environment startup log will be displayed

  5. The single project of springboot can also be operated like this

  6. Firstly, the fifth method is recommended. It is more troublesome to upload the local docker. First, the packaged image will be large, and the upload will also be time-consuming

  7. Finally, if you configure the server's docker and report an error, it is the second step of section 5.Don't think about uninstalling.I had this error at the time. I also found a lot of tutorials on the Internet, and then uninstalled Dafa, which is boundless. In fact, if you think about it for yourself, you will know where the problem is

  8. Open port 2375, be sure to close it, because this port, as long as I know your server IP address, I can connect to the docker service, and then pull to your mirror...firewall, security group, designated IP, certificate Can be processed, this place must be paid attention to

Guess you like

Origin blog.csdn.net/qq_38637558/article/details/105154483