Detailed usage of docker-maven-plugin

Detailed usage of docker-maven-plugin

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 packaging, write a Dockerfile file, create a new image based on the base image, upload the jar package (or war package) to the virtual machine and copy it to the JDK container. (Too much trouble)
  • Automatic deployment via Maven plugin. This is also a method often used in actual enterprise development.

Maven plugin automatic deployment steps

Written at the beginning: This method has loopholes and can be easily remotely inserted into the mining machine image by hackers. Be careful when using it. If 2375 is opened and no IP restriction is imposed, it will be pulled into mining. . . It is recommended to use CA encryption port

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

Executing the Maven command locally is a remote operation for the host machine. The remote operation of Docker is closed by default. Open port 2375 first.

First, execute the command on the host machine and modify the configuration file (centos 7)

vi /lib/systemd/system/docker.service

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

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

unix://var/run/docker.sock : unix socket, local clients will use this to connect to the Docker Daemon

tcp://0.0.0.0:2375 : TCP socket, which means that any remote client is allowed to connect to Docker Daemon through port 2375.

turn out to be

After

If it is centos7, modify the following

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375

2. Refresh the configuration and restart the service

systemctl daemon-reload //Load Docker daemon thread systemctl restart docker //Restart Docker

3. Configure container firewall

Even if port 2375 is opened, it cannot be accessed from the outside and can only be accessed from within. You need to configure the firewall. If Alibaba Cloud is not configured, be careful of being pulled into mining-_-, this is my school server, you need a VPN to access it, it doesn't matter

This is closed.

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

Turn off selinux

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

insert image description here

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

systemctl status firewalld (check firewall status)
secon (check selinux status) 

insert image description here

Alibaba Cloud recommends configuring security curses

At this time I connected to docker and succeeded

4. Add configuration in pom.xml

Dockerfile will be automatically generated with the following configuration

<build>
        <finalName>testDocker</finalName>
        <plugins>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <!--docker maven plugin-->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.1.0</version>
                <!--Configuration section-->
                <configuration>
                    <!--Modify the content of the imageName node to the private warehouse address and port, plus the image id and TAG, we want to transfer it directly to the private server-->
                    <!--Configure the final generated image name, in docker images, we take the project name: version -->
                    <imageName>172.19.240.208:5000/${project.artifactId}:${project.version}</imageName>
                    <!--Base image, equivalent to from--> in Dockerfile
                    <baseImage>ascdc/jdk8</baseImage>
                    <!--Entry point, project.build.finalName is the filename tag content under the build tag under the project tag, testDocker-->
                    <!--Equivalent to starting the container, java-jar/testDocker.jar will be automatically executed-->
                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                    <!--Whether to push to docker private warehouse-->
                    <pushImage>true</pushImage>
                    <registryUrl>172.19.240.208:5000</registryUrl>

                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <!--Which file is uploaded to Docker, equivalent to add testDocker.jar in Dockerfile /-->
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                    <dockerHost>http://172.19.240.208:2375</dockerHost>
                </configuration>
            </plugin>
        </plugins>
    </build>

Note that there are three points to push to a private repository, and the premise is that the container is in the started state

<!-- 1. Add a registryUrl node, the content is the private warehouse address and port (I set port 5000 here) -->
<registryUrl>your ip:5000</registryUrl>

<!-- 2. Add pushImage node-->
<pushImage>true</pushImage>

<!-- 3. Modify the content of the imageName node to the private warehouse address and port, add the image id and TAG, and the name in the warehouse is your project name: version-->
<imageName>yourip:5000/${project.artifactId}:${project.version}</imageName>

Run mvn clean and mvn install and put it in the local repository first.

[External link image transfer failed. The source site may have an anti-hotlink mechanism. It is recommended to save the image and upload it directly (img-84l0HMwJ-1579593153706)(/Users/zhangye/Library/Application Support/typora-user-images/image-20200120214402887.jpg)]

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

[External link image transfer failed. The source site may have an anti-hotlink mechanism. It is recommended to save the image and upload it directly (img-wdYBT027-1579593153707)(/Users/zhangye/Library/Application Support/typora-user-images/image-20200120214544482.jpg)]

There was an error 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]

I checked on Baidu and many people said that I need to log in. In fact, I don’t need to log in, nor does the repository not exist. In fact, there is no jdk1.8 image file on my docker, and I need to download one myself. I can docker search jdk8 and pull one, or upload the tar package myself and then create one with Dockerfile. I pulled one directly

insert image description here

docker images

insert image description here

Change the base image name in the project

insert image description here

Successfully built and pushed

insert image description here

[External link image transfer failed. The source site may have an anti-hotlink mechanism. It is recommended to save the image and upload it directly (img-SAUhrnA3-1579593153710)(/Users/zhangye/Library/Application Support/typora-user-images/image-20200121154702289.jpg)]

insert image description here

View Mirror

insert image description here

View Warehouse

insert image description here

This is the end of this article about the detailed usage of docker-maven-plugin. For more information about the usage of docker-maven-plugin, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The docker-maven-plugin plugin cannot pull the corresponding jar package
  • Summary of the dockerfile-maven-plugin usage guide
  • Use of Maven plugin docker-maven-plugin
  • dockerfile-maven-plugin minimalist tutorial (recommended)
  • Teach you how to use docker-maven-plugin to automate deployment

<<:  MySQL database Shell import_table data import

>>:  Solution to define the minimum height of span has no effect

Recommend

About MYSQL, you need to know the data types and operation tables

Data Types and Operations Data Table 1.1 MySQL ty...

CocosCreator classic entry project flappybird

Table of contents Development Environment Game en...

Detailed examples of variable and function promotion in JavaScript

js execution Lexical analysis phase: includes thr...

Vue implements a simple shopping cart example

This article example shares the specific code of ...

Example analysis of mysql non-primary key self-increment usage

This article uses an example to illustrate the us...

MySQL online deadlock analysis practice

Preface I believe that everyone has had a simple ...

Detailed process of decompressing and installing mysql5.7.17 zip

1. Download address https://dev.mysql.com/downloa...

Native js custom right-click menu

This article example shares the specific code of ...

Summary of H5 wake-up APP implementation methods and points for attention

Table of contents Preface Jump to APP method URL ...

Share 9 Linux Shell Scripting Tips for Practice and Interviews

Precautions 1) Add interpreter at the beginning: ...

A record of the pitfalls of the WeChat applet component life cycle

The component lifecycle is usually where our busi...

Solution for Docker container not recognizing fonts such as Songti

Problem background: When using docker to deploy t...

Summary of the three stages of visual designer growth

Many people have read this book: "Grow as a ...

In-depth explanation of MySQL stored procedures (in, out, inout)

1. Introduction It has been supported since versi...

HTML css js implements Tab page sample code

Copy code The code is as follows: <html xmlns=...