Teach you how to use docker-maven-plugin to automate deployment

Teach you how to use docker-maven-plugin to automate deployment

1. Introduction to docker-maven-plugin

In our continuous integration process, project engineering generally uses Maven to compile and package, and then generate images. By putting the images online, we can greatly improve the online efficiency, and at the same time, we can quickly and dynamically expand the capacity and quickly roll back, which is really convenient. The docker-maven-plugin plugin is designed to help us automatically generate images and push them to the warehouse through simple configuration in Maven projects.

**effect:

When compiling a project, a docker image can be automatically generated and pushed to a remote repository. You only need to configure it properly in the Maven configuration file pom.xml**

Example 1 (automatically generating a docker image during compilation):

1. Maven configuration:

<plugin>
          <groupId>com.spotify</groupId>
           <artifactId>docker-maven-plugin</artifactId>
           <version>1.0.0</version>
           <configuration>
           <!--Note that imageName must conform to the regular [a-z0-9-_.], otherwise the build will not succeed-->
           <imageName>myserver:v1</imageName>
           <!-- The directory of the Dockerfile is specified, so you need to create a docker directory under the project's src/main and configure the Dockerfile file in its directory-->
           <dockerDirectory>${project.basedir}/src/main/resources/docker</dockerDirectory>
           <skipDockerBuild>false</skipDockerBuild>
           <!-- The contents of resources will be copied to dockerDirectory (that is, the build context) -->
           <resources>
                <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
                </resource>
          </resources>
     </configuration>
</plugin>

2. Then in the project's src\main\resources\docker (the dockerDirectory directory configured above), create a file named Dockerfile with the following content:

FROM java:8
MAINTAINER blue
ADD mydocker-0.0.1-SNAPSHOT.jar mydocker.jar
ENTRYPOINT ["java", "-jar", "/mydocker.jar"]

3. Set system environment variables to specify the host and port of the docker daemon that needs to be connected. As mentioned earlier, docker is a C/S architecture, docker-maven-plugin plays the role of client, and the server needs environment variables to specify

insert image description here

4. Execute mvn clean install docker:build. After the project is compiled, the image is automatically built. Execute docker images to check whether the image exists:

insert image description here

Example 2 (pushing the image to the warehouse, based on Example 1):

1. Open the Maven configuration file setting.xml and add the warehouse account information:

<servers>
    <server>
        <id>docker-hub</id>
        <username>blueiii</username>
        <password>xxxx</password>
        <configuration>
          <email>[email protected]</email>
        </configuration>
    </server>
  </servers>

2. Modify the pom.xml file, imageName must be consistent with the warehouse path:

<imageName>blueiii/mydocker:v1</imageName>

3. Modify the pom.xml file and add the following configuration

<pushImage>true</pushImage>
<serverId>docker-hub</serverId>
<registryUrl>https://hub.docker.com/</registryUrl>

4. Also execute mvn clean install docker:build to automatically build the image and upload it to docker hub:

insert image description here

This is the end of this article about how to use docker-maven-plugin to automate deployment. For more information about docker maven plugin automated deployment, 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
  • Detailed usage of docker-maven-plugin
  • Use of Maven plugin docker-maven-plugin
  • dockerfile-maven-plugin minimalist tutorial (recommended)

<<:  Correct way to write empty links to prevent page jumps after clicking a href # problem

>>:  How to solve the problem of left alignment of the last line in flex layout space-between

Recommend

HTML displays ellipsis beyond the text... implemented through text-overflow

You need to apply CSS to div or span at the same t...

Detailed graphic explanation of MySql5.7.18 character set configuration

Background: A long time ago (2017.6.5, the articl...

How to implement web stress testing through Apache Bench

1. Introduction to Apache Bench ApacheBench is a ...

HTML uses the title attribute to display text when the mouse hovers

Copy code The code is as follows: <a href=# ti...

A brief discussion on the VUE uni-app life cycle

Table of contents 1. Application Lifecycle 2. Pag...

jQuery plugin to implement minesweeper game (3)

This article shares the third article on how to u...

The images in HTML are directly replaced by base64 encoded strings

Recently, I came across a webpage that had images ...

Complete steps to upgrade Nginx http to https

The difference between http and https is For some...

How to write transparent CSS for images using filters

How to write transparent CSS for images using filt...

js data types and their judgment method examples

js data types Basic data types: number, string, b...

How to track users with JS

Table of contents 1. Synchronous AJAX 2. Asynchro...

How to set up the terminal to run applications after Ubuntu starts

1. Enter start in the menu bar and click startup ...

SQL implementation of LeetCode (183. Customers who have never placed an order)

[LeetCode] 183.Customers Who Never Order Suppose ...

VMware Tools installation and configuration tutorial for Ubuntu

Some time ago, the blogger installed the Ubuntu s...