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 use docker-maven-plugin

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

Share

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

Editor to share with you how to use docker-maven-plugin, I hope you will get something after reading this article. Let's discuss it together.

Docker-Maven-Plugin

There are two ways to deploy microservices:

Manual deployment: first, generate a jar package (or war package) based on the source code package, write a Dockerfile file, create a new image based on the basic image, upload the jar package (or war package) to the virtual machine and copy it to the JDK container. (too much trouble)

Automatically deployed through the Maven plug-in. This is also a method often used in the actual development of enterprises.

Maven plug-in automatic deployment steps

Written at the front: this method has loopholes and is easy to be remotely put into the mirror image of the mining machine by hackers. When opened, you need to take precautions. If you open 2375, you will be dragged to mine without ip restrictions. CA encrypted port is recommended

1. Modify the docker configuration of the host and open port 2375 to allow remote access.

Local execution of the maven command is a remote operation for the host. The remote operation of docker is turned off by default. Port 2375 is opened first.

First execute the command on the host to modify the configuration file (centos 7)

Vi / lib/systemd/system/docker.service

Add configuration-H tcp://0.0.0.0:2375-H unix:///var/run/docker.sock after ExecStart=

ExecStart=/usr/bin/dockerd-H tcp://0.0.0.0:2375-H unix://var/run/docker.sock\

Unix://var/run/docker.sock:unix socket, which will be used by local clients to connect to Docker Daemon

Tcp://0.0.0.0:2375:tcp socket, which allows any remote client to connect to the Docker Daemon through port 2375.

It turns out

After modification

If it is centos7, the following is changed to

ExecStart=/usr/bin/dockerd-H fd://-H tcp://0.0.0.0:23752, refresh configuration, restart service systemctl daemon-reload / / load docker daemon thread systemctl restart docker / / restart docker3, configure container firewall

Even if port 2375 is opened, it cannot be accessed externally, only internally, if it is to be accessible externally. We need to configure the firewall. If Aliyun is not configured, be careful to be dragged to mine-- I am a school server, and I need vpn to access it. It doesn't matter.

This place is closed.

Use the command systemctl stop firewalld (turn off the firewall) systemctl disable firewalld (disable the firewall, boot will not start)

Close selinux

Change vi / etc/selinux/config,SELINUX=enforcing to disabled

After the restart is complete, check the firewall and selinux status

Systemctl status firewalld (View Firewall status) secon (View selinux status)

Ali Yun recommends the configuration of safety curse

At this time, I connected to docker, and it was successful.

4. Add configuration in pom.xml

Dockerfile will be generated automatically with the following configuration

TestDocker org.springframework.boot spring-boot-maven-plugin com.spotify docker-maven-plugin 1.1.0 172.19.240.208ascdc/jdk8 5000 project.artifactId: ${project.version} ascdc/jdk8 ["java" "- jar" "/ ${project.build.finalName} .jar"] true 172.19.240.208 project.build.directory 5000 / ${jar} ${project.build.finalName} .jar http://172.19.240.208:2375

Note that there are three points from push to private warehouse, and only if the container is started.

Your ip:5000true, your ip:5000/$ {project.artifactId}: ${project.version}

Mvn clean,mvn install, put it in the local warehouse first.

Then execute the mvn docker:build command to create the image. If you want to upload it, add a-DpushImage parameter.

There was a mistake when running.

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.1.0:build (default-cli) on project demo:

Exception caught: pull access denied for jdk1.8, repository does not exist or may require 'docker login':

Denied: requested access to the resource is denied-> [Help 1]

Baidu checked, many people said to log in, in fact, it is not to log in, it is not that the warehouse does not exist, in fact, there is no jdk1.8 image file on my docker, you need to docker search jdk8,pull one, or upload the tar package yourself and Dockerfile to get one. I directly pull one.

Docker images

Change the basic image name in the project

Build it successfully and push it

View Mirror

View the warehouse

After reading this article, I believe you have a certain understanding of "how to use docker-maven-plugin". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

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