第一步:需要在springboot 项目中增加
pom
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.13</version> <configuration> <!--镜像名:建议 仓库仓库地址 + 镜像文件夹 + 项目名字--> <imageName>10.100.20.243:8003/duoyuanhua/${project.artifactId}</imageName> <!--dockerfile 所在地址--> <dockerDirectory>src/main/docker</dockerDirectory> <!--仓库仓库地址--> <dockerHost>http://10.100.20.243:8003</dockerHost> <resources> <resource> <targetPath>/</targetPath> <!--镜像文件夹--> <directory>duoyuanhua</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin>
dockerfile
FROM openjdk:8-jdk-alpine VOLUME /tmp ADD marketing-1.0-SNAPSHOT.jar app.jar RUN sh -c 'touch /app.jar' ENV JAVA_OPTS="" ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
执行命令:
mvn clean package docker:build -Dmaven.test.skip=true
报错:
[INFO] --- docker-maven-plugin:0.4.13:build (default-cli) @ marketing --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 41.779 s [INFO] Finished at: 2021-04-15T18:27:11+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project marketing: Exception caught: basedir duoyuanhua does not exist -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
需要去docker开通tcp传输:
vim /usr/lib/systemd/system/docker.service
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
保存,在重启docker
systemctl daemon-reload //重新读取配置文件
systemctl restart docker //重新启动服务
lsof -i:2375 // 查看2375端口是否开启
netstat antlp | grep 2375 // 也可以查看
再次执行打包:
mvn clean package docker:build -Dmaven.test.skip=true