主頁(yè) > 知識(shí)庫(kù) > 在Idea中使用Docker部署SpringBoot項(xiàng)目的詳細(xì)步驟

在Idea中使用Docker部署SpringBoot項(xiàng)目的詳細(xì)步驟

熱門(mén)標(biāo)簽:網(wǎng)站建設(shè) 美圖手機(jī) 硅谷的囚徒呼叫中心 檢查注冊(cè)表項(xiàng) 智能手機(jī) 百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式 阿里云 使用U盤(pán)裝系統(tǒng)

前言

項(xiàng)目需要:

安裝Dockeridea中安裝docker插件,并配置docker一個(gè)SpringBoot項(xiàng)目創(chuàng)建Dockerfile

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

下載地址:官網(wǎng)下載 Docker

安裝

一直下一步就行

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

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

測(cè)試是否安裝成功

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 安裝

2.配置Docker服務(wù)

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

三、創(chuàng)建SpringBoot項(xiàng)目,修改pom.xmlspringMVC 項(xiàng)目,訪問(wèn) localhost:8080/hello 顯示 hello 字符串

@RequestMapping("/hello")
  @ResponseBody
  public String hello () {
    return "hello";
  }

1.配置pom.xml 文件

<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.創(chuàng)建Docker 文件

在main文件夾下創(chuàng)建一個(gè)docker文件夾,并在里面創(chuàng)建一個(gè)Dockerfile文件。xxxxx.jar 是使用maven打包后復(fù)制進(jìn)來(lái)的。

Dockerfile 文件內(nèi)容:

# 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包復(fù)制進(jìn)docker目錄下。

配置Dockerfile配置

運(yùn)行

運(yùn)行成功

測(cè)試

使用docker 檢查容器是否啟動(dòng):

測(cè)試項(xiàng)目是否啟動(dòng):

總結(jié)

今天學(xué)了下Docker容器,基本的命令學(xué)會(huì)了,但是一直沒(méi)弄懂怎么使用。借此機(jī)會(huì)就花費(fèi)時(shí)間進(jìn)行學(xué)習(xí)。目前只是會(huì)用,后面會(huì)補(bǔ)上步驟詳細(xì)描述。

到此這篇關(guān)于在Idea中使用Docker部署SpringBoot項(xiàng)目的文章就介紹到這了,更多相關(guān)Docker部署SpringBoot項(xiàng)目?jī)?nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

標(biāo)簽:山南 煙臺(tái) 通遼 湘潭 湖北 賀州 黃山 懷化

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《在Idea中使用Docker部署SpringBoot項(xiàng)目的詳細(xì)步驟》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266