1.修改linux服務(wù)器docker配置文件
vim /usr/lib/systemd/system/docker.service
添加配置
ExecStart=/usr/bin/dockerd
-H fd:// --containerd=/run/containerd/containerd.sock
-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
重啟docker
systemctl daemon-reload
systemctl restart docker
2.Idea下載docker插件
3.修改項(xiàng)目pom文件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
<mainClass>com.Main8090</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<!--將插件綁定在某個(gè)phase執(zhí)行-->
<executions>
<execution>
<id>build-image</id>
<!--將插件綁定在package這個(gè)phase上。也就是說,用戶只需執(zhí)行mvn package ,就會自動執(zhí)行mvn docker:build-->
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<!--指定生成的鏡像名 ${project.artifactId} -->
<imageName>idea2021test</imageName>
<!--指定標(biāo)簽-->
<imageTags>
<imageTag>latest</imageTag>
</imageTags>
<!-- 指定 Dockerfile 路徑 ${project.basedir}:項(xiàng)目根路徑下-->
<dockerDirectory>${project.basedir}</dockerDirectory>
<!--指定遠(yuǎn)程 docker api地址-->
<dockerHost>http://101.200.201.196:2375</dockerHost>
<!-- 這里是復(fù)制 jar 包到 docker 容器指定目錄配置 -->
<resources>
<resource>
<targetPath>/</targetPath>
<!--jar 包所在的路徑 此處配置的 即對應(yīng) target 目錄-->
<directory>${project.build.directory}</directory>
<!-- 需要包含的 jar包 ,這里對應(yīng)的是 Dockerfile中添加的文件名 -->
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<!-- 以下兩行是為了docker push到DockerHub使用的。 -->
<!--<serverId>docker-hub</serverId>-->
<!--<registryUrl>https://index.docker.io/v1</registryUrl>-->
</configuration>
</plugin>
</plugins>
</build>
4.打包、build
---> Running in 0ff0ece2e746
Removing intermediate container 0ff0ece2e746
---> 76846947b2eb
Step 4/4 : ENTRYPOINT ["java","-jar","/app.jar"]
---> Running in fac72c653afd
Removing intermediate container fac72c653afd
---> f7866a998d4e
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built f7866a998d4e
Successfully tagged idea2021test:latest
[INFO] Built idea2021test
[INFO] Tagging idea2021test with latest
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:43 min
[INFO] Finished at: 2021-06-17T21:02:25+08:00
表示build成功
5.創(chuàng)建容器
6.配置映射端口
7.運(yùn)行
到此這篇關(guān)于Idea配置Docker 遠(yuǎn)程部署的文章就介紹到這了,更多相關(guān)idea部署遠(yuǎn)程docker內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!