Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Implementation of Docker Project deployment in IDEA

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Implementation of Docker project deployment in IDEA? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Docker configuration

Modify the configuration file

Open the Docker configuration file: vim / usr/lib/systemd/system/docker.service comment out the following line: # ExecStart=/usr/bin/dockerd-H fd://-- containerd=/run/containerd/containerd.sock write a new line: ExecStart=/usr/bin/dockerd-H tcp://0.0.0.0:2375-H unix:///var/run/docker.sock reload configuration file and boot: systemctl daemon-reloadsystemctl start docker

As shown in the following figure:

IDEA configuration Docker

Install the Docker plug-in

Configure Docker information

To configure Docker in the settings, you need to configure API URL. Connection successful appears as follows:

Project building

Create a new springboot project

To build a project through IDEA, you don't need to choose anything, just go to the next step:

Modify the pom file

There are two main points:

Add to the 1.properties tag

Demo

two。 Add a new plugin tag

Com.spotify docker-maven-plugin 1.2.1 ${docker.image.prefix} / ${project.artifactId} / ${project.build.directory} ${project.build.finalName} .jar

Here is the complete pom file:

4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.1.RELEASE com.example demo 0.0.1 demo Demo project for Spring Boot 1.8 demo org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.junit .vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin com.spotify docker-maven-plugin 1.2.1 ${docker.image.prefix} / ${project.artifactId} / ${ Project.build.directory} ${project.build.finalName} .jar

Create a new Dockerfile file

Need to create a new Dockerfile file in the root directory

# specify the basic image on which to customize FROM java:8# maintainer information MAINTAINER zhouzhaodong # the / tmp directory here will be automatically mounted as anonymous volumes at run time, and any information written to / tmp will not be recorded into the target/demo-1.0.0.jar in the container storage layer VOLUME / tmp# replication context directory and executed as COPY target/demo-0.0.1.jar demo-1.0.0.jar#bash in the container. Make demo-1.0.0.jar accessible to # RUN to create a new layer, execute these commands on it, and after execution, the changes in the commit layer form a new mirror. RUN bash-c "touch / demo-1.0.0.jar" # states that the runtime container provides a service port, which is just a declaration, and the service EXPOSE 808 will not open this port at run time because of this declaration. EXPOSE 808 specifies the container launcher and parameters "" ENTRYPOINT ["java", "- jar", "demo-1.0.0.jar"]

Create a new controller file

Don't forget to add web dependencies to the pom file.

@ RestControllerpublic class testController {@ RequestMapping ("/") public String test () {return "test Docker";}}

Maven packing

Install Packaging:

Generate the jar package:

New configuration

Create a new Dockerfile running configuration:

Add the following information, find the Dockerfile file you wrote, and configure the port mapping:

Generate Docker image and run it

Just run the Dockerfile running configuration you just created:

After a successful run, the log window will display the information about the project running:

Visit the corresponding address to display the information we entered:

After reading the above, have you mastered the implementation of Docker project deployment in IDEA? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report