maven项目构建docker镜像并上传到harbor私服

windows版本安装docker地址https://www.cnblogs.com/wyt007/p/10656813.html

windows本地安装Docker Desktop,并且用idea或者eclipse集成docker插件

1,项目中编写Dockerfile文件,放在与项目同级目录下:

Dockerfile

 
  1. FROM java:8
  2. VOLUME /tmp
  3. ARG JAR_FILE=target/build/*.jar
  4. COPY ${JAR_FILE} spring-crm.jar
  5. COPY target/build/lib lib
  6. COPY target/build/resources resources
  7. ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dloader.path=.,resources,lib","-jar","/spring-crm.jar","--spring.profiles.active=test"]

2,pom文件末尾添加:

34.92.172.25:8888  docker的harbor私服在的服务地址
xhl`  harbor私服项目名




com.spotify
docker-maven-plugin
0.4.13





docker-registry  指定docker私服在maven的settings配置的熟悉
${docker.repository}/${docker.registry.name}/${docker.image.prefix}-${project.artifactId}
${docker.repository}
true  push镜像到私服
./



latest



/
${project.build.directory}
${project.build.finalName}.jar






 
  docker-build  docker的build操作
  package
 
  build
 

 
 tag-image  给docker镜像打tag
 package
 
  tag
 

${docker.repository}/${docker.registry.name}/${docker.image.prefix}-${project.artifactId}
${docker.repository}/${docker.registry.name}/${docker.image.prefix}-${project.artifactId}



push-image  docker的push操作
deploy

push


${docker.repository}/${docker.registry.name}/${docker.image.prefix}-${project.artifactId}



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私服地址访问的用户名和密码以及邮件

 
  1. docker-registry
  2. xxx
  3. xxx
  4. [email protected]

除了命令方式,还有直接通过k8s命令运行镜像

你可能感兴趣的:(docker)