Idea部署远程Docker并配置文件
导读
1.修改linux服务器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.修改项目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> <!--将插件绑定在某个phase执行--> <executions> <execution> <id>build-image</id> <!--将插件绑定在package这个phase上。也就是说,用户只需执行mvn package ,就会自动执行mvn docker:build--> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <!--指定生成的镜像名 ${project.artifactId} --> <imageName>idea2021test</imageName> <!--指定标签--> <imageTags> <imageTag>latest</imageTag> </imageTags> <!-- 指定 Dockerfile 路径 ${project.basedir}:项目根路径下--> <dockerDirectory>${project.basedir}</dockerDirectory> <!--指定远程 docker api地址--> <dockerHost>http://101.200.201.196:2375</dockerHost> <!-- 这里是复制 jar 包到 docker 容器指定目录配置 --> <resources> <resource> <targetPath>/</targetPath> <!--jar 包所在的路径 此处配置的 即对应 target 目录--> <directory>${project.build.directory}</directory> <!-- 需要包含的 jar包 ,这里对应的是 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.创建容器
6.配置映射端口
7.运行