Microservice automation. 05 Use of idea plug-in

Docker is used in combination with Idea plug-in

1, Install docker plug-in

1. New idea project

2. Check whether there is a Docker in the plug-in

3. In docker The port number is indicated in the service file

modify Docker Service file , Comment out "ExecStart" This line and add the following information
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://
Reload profile
systemctl daemon-reload
Restart service
systemctl restart docker

4. Firewall operation

firewall-cmd --zone=public --add-port=2375/tcp --permanent && firewall-cmd --reload && firewall-cmd --list-ports

5. Configure Docker

You can directly pull the image here, because I don't pull it when I have it

6. Build the Springboot project, generate the Dockerfile, and complete the image generation

Remove the jar package

Create a new file and put it in the jar package:

dockerfile-v1: change to dockerfile

#1. Specify the basic image
FROM openjdk:8-jdk-alpine
#2. Maintainer information
MAINTAINER xyz "xyz@qq.com"
#3. Create the / tmp directory and persist it to the Docker data folder, because the embedded Tomcat container used by Spring Boot uses / tmp as the working directory by default
#4. Copy test1 Jar into the container (this is different from the one click release of docker plug-in in the later idea)
ADD test.jar /test.jar
#5. Set time zone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
#6. Declare that the runtime container provides a service port. This is just a declaration. The application will not open the service of this port because of this declaration at runtime
#7. Specify the container startup program and parameters (equivalent to executing jar package with cmd command in the container)
ENTRYPOINT ["java","-jar","/test.jar"]
#The following script specifies the additional parameters specified when the springboot project starts
#ENTRYPOINT ["java","-jar","/test.jar","--spring.config.location=/usr/local/project/docker/xxl-job/config/application.yml"]

Compile image

docker build -t demo:1.0 .


docker run -itd --name test01 -p 8848:8080 demo:1.0

Visit successful

II. Private server construction

1. Pull the registry image (choose to build the registry of version 2.7 here, do not use the latest version, and there is a BUG)

docker pull registry:2.7


2. Open the container

docker run -d \
--name myregistry \
-p 5000:5000 \
-v /usr/local/docker/registry:/var/lib/registry \
--restart=always \

3. Verify whether the construction is successful


4. Let docker trust the private image warehouse address

vi /etc/docker/daemon.json
stay daemon.json Add the following content to the, whose value is the registration server (registry) of IP And port
"insecure-registries" :[ "" ]
Modified file
restart docker
systemctl restart docker

3, Use of private warehouses

After creating a private warehouse, you can use it docker tag To mark an image and push it to the warehouse
First view the existing images on the local machine and select one of them to upload
Mirror mark (push The mirror must be marked before , custom repository Capital letters are not allowed )
docker tag Custom image name[:edition] Private service IP:port/Warehouse name[:edition]
docker tag demo:1.0
Execute view all mirrors
docker images
Image upload
docker push

View all images of the registered server


The demo has entered the warehouse

Download Image from registry

docker pull

4, Idea one click deployment

Configure maven plug-in

① . create a new TestController class

package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class TestController {

    public String test(){
        return "hello world";


② Package the project

③ . pom file import plug-in

                            <!--If package I don't want to use it docker pack,Just comment this out goal-->


Precautions for using plug-ins
① The plug-in relies on a Host with Docker to complete the construction of the image
② . since the plug-in needs to access the Docker Host, it requires the Docker Host to open the TCP management port and allow access (complete)
③ . the machine using this plug-in needs to be configured with DOCKER_HOST option, pointing to the corresponding port of Docker Host (incomplete)

That is, configure the relevant environment variable docker under windows_ HOST= tcp://


After modifying the system variable, you need to restart the development tool to take effect. At the beginning, you will be prompted that the image upload failed. After reading the error, you can upload it ip It's still the default , restart IDEA That's it
4. The plug-in relies on the image warehouse to build and publish images. Users need to provide the login information of the image warehouse to support POM Settings and Settings set up , Alibaba cloud images or private image warehouses can be used to create images
5. Need in maven/conf/ Lower setting.xml to configure
This file is in maven Under the directory, you can cd $M2_HOME/conf get into. stay pluginGroups Add one in com.spotify



2. Dockerfile file of new project

3. Add maven command


clean package dockerfile:build -Dmaven.test.skip=true







Keywords: Microservices intellij-idea

Added by metroblossom on Sat, 05 Mar 2022 13:31:06 +0200