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

Detailed explanation of the properties and functions of Vuex

Table of contents What is Vuex? Five properties o...

CSS3 realizes the red envelope shaking effect

There is a requirement to realize the shaking eff...

Solution to Ubuntu 20.04 Firefox cannot play videos (missing flash plug-in)

1. Flash plug-in package download address: https:...

Teach you how to deploy Vue project with Docker

1.Write in front: As a lightweight virtualization...

Detailed explanation of the use of props in React's three major attributes

Table of contents Class Component Functional Comp...

How to allow all hosts to access mysql

1. Change the Host field value of a record in the...

How to uninstall MySQL 5.7 on CentOS7

Check what is installed in mysql rpm -qa | grep -...

What are the benefits of using B+ tree as index structure in MySQL?

Preface In MySQL, both Innodb and MyIsam use B+ t...

How to set up scheduled backup tasks in Linux centos

Implementation Preparation # Need to back up the ...

Use Vue3+Vant component to implement App search history function (sample code)

I am currently developing a new app project. This...

Detailed example of how to implement transaction commit and rollback in mysql

Recently, we need to perform a scheduled migratio...

Detailed explanation of HTML programming tags and document structure

The purpose of using HTML to mark up content is t...