一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

云服務器|WEB服務器|FTP服務器|郵件服務器|虛擬主機|服務器安全|DNS服務器|服務器知識|Nginx|IIS|Tomcat|

服務器之家 - 服務器技術 - 服務器知識 - 在Idea中使用Docker部署SpringBoot項目的詳細步驟

在Idea中使用Docker部署SpringBoot項目的詳細步驟

2021-05-09 18:04胸大的請先講 服務器知識

這篇文章主要介紹了在Idea中使用Docker部署SpringBoot項目的詳細教程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

前言

項目需要:

安裝Dockeridea中安裝docker插件,并配置docker一個SpringBoot項目創建Dockerfile

一、下載、安裝、配置Docker下載Docker

下載地址:官網下載 Docker

安裝

一直下一步就行

配置路徑:Settings–General 勾選 Expose daemon on tcp://localhost:2375 without TLS

在Idea中使用Docker部署SpringBoot項目的詳細步驟

設置鏡像,提高下載鏡像的速度https://xaiqlt1z.mirror.aliyuncs.com

在Idea中使用Docker部署SpringBoot項目的詳細步驟

測試是否安裝成功

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
C:\Users\msi>docker -v
Docker version 19.03.12, build 48a66213fe
 
C:\Users\msi> docker run hello-world
 
Hello from Docker!
This message shows that your installation appears to be working correctly.
 
To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  (amd64)
 3. The Docker daemon created a new container from that image which runs the
  executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
  to your terminal.
 
To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
 
Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/
 
For more examples and ideas, visit:
 https://docs.docker.com/get-started/

二、Idea 安裝Docker插件

1.安裝docker插件在idea中: file--Plugins--Marketplace 搜索 Docker 安裝

在Idea中使用Docker部署SpringBoot項目的詳細步驟

2.配置Docker服務

file – 搜索docker – 選擇Docker – 右側添加一個Docker
Connection successful 顯示,表示 Docker鏈接成功

在Idea中使用Docker部署SpringBoot項目的詳細步驟

三、創建SpringBoot項目,修改pom.xmlspringMVC 項目,訪問 localhost:8080/hello 顯示 hello 字符串

?
1
2
3
4
5
@RequestMapping("/hello")
  @ResponseBody
  public String hello () {
    return "hello";
  }

1.配置pom.xml 文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version> 1.2.1</version>
        <executions>
          <execution>
            <id>build-image</id>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <imageName>${project.artifactId}</imageName>
          <imageTags>
            <imageTag>latest</imageTag>
          </imageTags>
          <dockerDirectory>${project.basedir}</dockerDirectory>
          <dockerHost>http://localhost:2375</dockerHost>
          <resources>
            <resource>
              <targetPath>/</targetPath>
              <directory>${project.build.directory}</directory>
              <include>${project.build.finalName}</include>
            </resource>
          </resources>
        </configuration>
      </plugin>
    </plugins>
  </build>

2.創建Docker 文件

在main文件夾下創建一個docker文件夾,并在里面創建一個Dockerfile文件。xxxxx.jar 是使用maven打包后復制進來的。

在Idea中使用Docker部署SpringBoot項目的詳細步驟

Dockerfile 文件內容:

?
1
2
3
4
5
6
7
8
9
10
11
12
# From java image, version : 8
FROM java:8
 
# 掛載app目錄
VOLUME /app
 
# COPY or ADD to image
COPY demo-0.0.1-SNAPSHOT.jar app.jar
 
RUN bash -c "touch /app.jar"
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

maven打包,將其target目錄下的jar包復制進docker目錄下。

配置Dockerfile配置

在Idea中使用Docker部署SpringBoot項目的詳細步驟

運行

在Idea中使用Docker部署SpringBoot項目的詳細步驟

運行成功

在Idea中使用Docker部署SpringBoot項目的詳細步驟

測試

使用docker 檢查容器是否啟動:

在Idea中使用Docker部署SpringBoot項目的詳細步驟

測試項目是否啟動:

在Idea中使用Docker部署SpringBoot項目的詳細步驟

總結

今天學了下Docker容器,基本的命令學會了,但是一直沒弄懂怎么使用。借此機會就花費時間進行學習。目前只是會用,后面會補上步驟詳細描述。

到此這篇關于在Idea中使用Docker部署SpringBoot項目的文章就介紹到這了,更多相關Docker部署SpringBoot項目內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://blog.csdn.net/qq_42428264/article/details/108504312

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品视频免费在线 | 千金肉奴隶免费观看 | 500福利第一导航 | 2012在线观看免费视频大全 | 国产精品1区2区 | 17岁俄罗斯csgo | 国产第一页在线视频 | 国产91精品在线观看 | 韩国甜性涩爱在线播放 | 亚洲精品片| 办公室里被迫高h | 欧美特黄特色aaa大片免费看 | 美艳教师刘艳第三部166 | 国内在线观看 | 亚洲欧美天堂 | 99在线视频免费 | 特级毛片全部免费播放器 | 深夜影院a | 亚洲天堂成人在线观看 | 无码一区国产欧美在线资源 | 俄罗斯毛片免费大全 | free性丰满hd性欧美人体 | 国产自产在线 | 2019天天干夜夜操 | 欧美一区二区三区免费观看视频 | 欧美三级免费观看 | 办公室恋情在线 | 女人张开腿让男人做爽爽 | 午夜精品久视频在线观看 | 亚洲第99页 | 国产一级一级一级成人毛片 | 久草热8精品视频在线观看 久草草在线视视频 | 欧美z0z0人禽交 | 男生和老师一起差差差 | 二区三区在线观看 | 垫底辣妹免费观看完整版 | 精品一区二区三区视频 | 免费成年网站 | 99re8在这里只有精品2 | 91久久碰国产 | 亚洲男人天堂久久 |