windows版本安装docker地址https://www.cnblogs.com/wyt007/p/10656813.html
windows本地安装Docker Desktop,并且用idea或者eclipse集成docker插件
1,项目中编写Dockerfile文件,放在与项目同级目录下:
Dockerfile
FROM java:8
VOLUME /tmp
ARG JAR_FILE=target/build/*.jar
COPY ${JAR_FILE} spring-crm.jar
COPY target/build/lib lib
COPY target/build/resources resources
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dloader.path=.,resources,lib","-jar","/spring-crm.jar","--spring.profiles.active=test"]
2,pom文件末尾添加:
<docker.repository>34.92.172.25:8888</docker.repository> docker的harbor私服在的服务地址
<docker.registry.name>xhl</docker.registry.name>` harbor私服项目名
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<!--<skipDocker>true</skipDocker>-->
<!--<skipDockerBuild>true</skipDockerBuild>-->
<!--<skipDockerPush>true</skipDockerPush>-->
<!--<skipDockerTag>true</skipDockerTag>-->
<serverId>docker-registry</serverId> 指定docker私服在maven的settings配置的熟悉
<imageName>${docker.repository}/${docker.registry.name}/${docker.image.prefix}-${project.artifactId}</imageName>
<registryUrl>${docker.repository}</registryUrl>
<pushImage>true</pushImage> push镜像到私服
<dockerDirectory>./</dockerDirectory>
<!--<dockerHost>http://34.92.172.25:2375</dockerHost>-->
<imageTags>
<!--docker的tag为项目版本号、latest-->
<imageTag>latest</imageTag>
</imageTags>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
<executions>
<execution>
<id>docker-build</id> docker的build操作
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>tag-image</id> 给docker镜像打tag
<phase>package</phase>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<image>${docker.repository}/${docker.registry.name}/${docker.image.prefix}-${project.artifactId}</image>
<newName>${docker.repository}/${docker.registry.name}/${docker.image.prefix}-${project.artifactId}</newName>
</configuration>
</execution>
<execution>
<id>push-image</id> docker的push操作
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<imageName>${docker.repository}/${docker.registry.name}/${docker.image.prefix}-${project.artifactId}</imageName>
</configuration>
</execution>
</executions>
</plugin>
3,生成docker镜像需要把Dockerfile文件和源文件放在一起
4,使用mvn clean,package就会自动打包生成docker镜像
5,docker images查看是否生成新的docker镜像
6,docker run -it -v /tmp/:/tmp/ -p 7088:7088 springboot-crm /bin/bash
docker详细文档见https://blog.csdn.net/weixin_40816738/article/details/90169007
maven的settings配置文件需要添加,配置docker私服地址访问的用户名和密码以及邮件
<server>
<id>docker-registry</id>
<username>xxx</username>
<password>xxx</password>
<configuration>
<email>xxx@qq.com</email>
</configuration>
</server>
除了命令方式,还有直接通过k8s命令运行镜像