Detailed process of installing the docker plugin in IntelliJ IDEA (2018 version)

Detailed process of installing the docker plugin in IntelliJ IDEA (2018 version)

1. Development Environment

Development Tools Version
IntelliJ IDEA 2018.1.6 (Community Edition)
Docker integration 181.5087.20

2. Install the docker plugin

1. Installation in Idea

Open Idea, go to File->Settings->Plugins->Install JetBrains plugin to enter the plugin installation interface, enter docker in the search box, you can see Docker integration, click the Install button on the right to install it. Restart Idea after installation.

After restarting, configure docker and connect to the remote docker service. Open the configuration interface from File->Settings->Build,Execution,Deployment->Docker.

Click the + sign to add a docker configuration, enter the Name and Engine API URL. The URL is the docker service address, and docker needs to enable the remote connection function. In CentOS, add the following configuration to the docker startup parameters to enable remote connection.

Configuration file location: /usr/lib/systemd/system/docker.service, configuration parameter item: ExecStart

-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375

2. Download the installation package and install it

Download the docker installation package from the JetBrains official website (http://plugins.jetbrains.com/plugin/7724-docker-integration), open Idea after downloading, open the file selection interface from File->Settings->Plugins->Install plugin from disk, select the zip installation package you just downloaded, and restart Idea after installation. The configuration is as above.

3. Spring Boot service docker deployment

1. Create a new Spring Boot project

You can refer to the sample project https://github.com/sealire/people/tree/tutorial and write a REST interface in the project as follows, which simply returns a string.

@RequestMapping(value = "test", method = RequestMethod.GET)
@ResponseBody
public Object test(HttpServletRequest request, @RequestParam String param) {
    return param;
}

Modify the pom file, add properties, and add plugin:

<properties>
    <docker.image.prefix>leesia</docker.image.prefix>
</properties>
 
<build>
	<plugins>
		<plugin>
			<groupId>com.spotify</groupId>
			<artifactId>docker-maven-plugin</artifactId>
			<version>1.0.0</version>
			<configuration>
				<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
				<dockerDirectory></dockerDirectory>
				<resources>
					<resource>
						<targetPath>/</targetPath>
						<directory>${project.build.directory}</directory>
						<include>${project.build.finalName}.jar</include>
					</resource>
				</resources>
			</configuration>
		</plugin>
	</plugins>
</build>

2. Configure the Dockerfile file

Create a new Dockerfile file in the project root directory with the following content:

FROM java:8
VOLUME /tmp
COPY target/resource-1.0-SNAPSHOT.jar resource.jar
RUN bash -c "touch /resource.jar"
EXPOSE 8080
ENTRYPOINT ["java","-jar","resource.jar"]
 
# docker run -d -p 18080:8080 --name docker-resource leesia/resource:1.0

The base image is java:8, and the copy command copies the resource jar under /target to the image. ENTRYPOINT is the command to start the container.

3. Create a Docker image

Package the project and execute the mvn clean package command in the idea Terminal to compile and package it. After packaging, a jar package will be generated in the target directory.

After generating the jar package, you can start the service locally for testing. After testing, configure the Docker image creation command. Enter the configuration interface from Run->Edit Configrations.

Click Docker, then click the + sign, add a docker command, enter Name, select Server, select the Dockerfile file, enter the image tag, and complete the configuration.

After the configuration is complete, execute this command,

If there are no errors, the Docker server will be connected and the image will be created. After creating the image, start the image on the Docker server and execute the following command to start the image:

docker run -d -p 18080:8080 --name docker-resource leesia/resource:1.0

-p binds the Docker server's port 18080 to the container's port 8080.

After the container is started, access the service interface. The interface parameter is a string and the character is returned.

This is the end of this article about installing the docker plugin for IntelliJ IDEA. For more information about installing the docker plugin for IDEA, 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:
  • idea uses docker plug-in to achieve one-click automated deployment
  • IDEA uses the Docker plug-in (novice tutorial)
  • How to use Docker plugin to remotely deploy projects to cloud servers in IDEA
  • Solve the problem of garbled logs after IDEA integrates Docker plug-in
  • Detailed tutorial on how to publish springboot projects through docker plug-in in IDEA

<<:  MySQL date and time addition and subtraction sample code

>>:  Example code for CSS pseudo-classes to modify input selection style

Recommend

Specific use of MySQL operators (and, or, in, not)

Table of contents 1. Introduction 2. Main text 2....

Style trigger effect of web page input box

<br />This example mainly studies two parame...

Install MySQL 5.7 on Ubuntu 18.04

This article is compiled with reference to the My...

MySQL executes commands for external sql script files

Table of contents 1. Create a sql script file con...

The difference between char, varchar and text field types in MySQL

In MySQL, fields of char, varchar, and text types...

Centos8 bridge static IP configuration method in VMware virtual machine

1. Make sure the network connection method is bri...

New ways to play with CSS fonts: implementation of colored fonts

What if you designers want to use the font below ...

Two methods to stretch the background image of a web page

There are two solutions: One is CSS, using backgro...

Node.js implements breakpoint resume

Table of contents Solution Analysis slice Resume ...

Detailed tutorial on compiling and installing python3.6 on linux

1. First go to the official website https://www.p...

IE6 web page creation reference IE6 default style

This is not actually an official document of IE. I...

Detailed explanation of Vue's monitoring properties

Table of contents Vue monitor properties What is ...