在Idea中使用Docker部署SpringBoot項目的詳細步驟
前言
項目需要:
安裝Dockeridea中安裝docker插件,并配置docker一個SpringBoot項目創(chuàng)建Dockerfile
一、下載、安裝、配置Docker下載Docker
下載地址:官網(wǎng)下載 Docker
安裝
一直下一步就行
配置路徑:Settings–General 勾選 Expose daemon on tcp://localhost:2375 without TLS

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

測試是否安裝成功
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服務
file – 搜索docker – 選擇Docker – 右側添加一個Docker
Connection successful 顯示,表示 Docker鏈接成功

三、創(chuàng)建SpringBoot項目,修改pom.xmlspringMVC 項目,訪問 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)建一個docker文件夾,并在里面創(chuàng)建一個Dockerfile文件。xxxxx.jar 是使用maven打包后復制進來的。

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包復制進docker目錄下。
配置Dockerfile配置

運行

運行成功

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

測試項目是否啟動:

總結
今天學了下Docker容器,基本的命令學會了,但是一直沒弄懂怎么使用。借此機會就花費時間進行學習。目前只是會用,后面會補上步驟詳細描述。
到此這篇關于在Idea中使用Docker部署SpringBoot項目的文章就介紹到這了,更多相關Docker部署SpringBoot項目內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
- Gitlab-runner+Docker實現(xiàn)自動部署SpringBoot項目
- idea快速實現(xiàn)將SpringBoot項目打包Docker鏡像并部署
- Docker部署SpringBoot應用的實現(xiàn)步驟
- Docker compose部署SpringBoot項目連接MySQL及遇到的坑
- Springboot服務Docker化自動部署的實現(xiàn)方法
- Springboot打包為Docker鏡像并部署的實現(xiàn)
- 詳解docker部署SpringBoot及替換jar包的方法
- docker安裝tomcat并部署Springboot項目war包的方法
- 利用Dockerfile部署SpringBoot項目的方法
- springboot整合docker部署實現(xiàn)兩種構建Docker鏡像方式
- 詳解springboot項目docker部署實踐
- 如何利用Docker部署一個簡單的springboot項目
相關文章
查看Docker停止容器占用的內(nèi)存的實現(xiàn)方法小結
要查看 Docker 停止的容器占用的內(nèi)存,可以通過以下幾種方法來實現(xiàn),Docker 提供了一些命令和工具來幫助你管理和監(jiān)控容器的資源使用情況,需要的朋友可以參考下2024-11-11
Docker 數(shù)據(jù)卷操作的實現(xiàn)
這篇文章主要介紹了Docker 數(shù)據(jù)卷操作的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-06-06
Docker容器生命周期 | kill和 stop的區(qū)別與聯(lián)系 | d
這篇文章主要介紹了Docker容器生命周期 | kill和 stop的區(qū)別與聯(lián)系 | docker pause/ unpause,本講內(nèi)容是從?Docker入門到進階里面抽離出來的內(nèi)容,從而使原文更加有序、重點突出,需要的朋友可以參考下2023-08-08

