环境
windows 10
docker-toolbox
virtualbox
步骤
1. 编辑POM文件
<plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.4.4</version> <executions> <execution> <id>tag-latest</id> <phase>deploy</phase> <goals> <goal>build</goal> <goal>tag</goal> <goal>push</goal> </goals> <configuration> <tag>latest</tag> </configuration> </execution> <execution> <id>tag-version</id> <phase>deploy</phase> <goals> <goal>build</goal> <goal>tag</goal> <goal>push</goal> </goals> <configuration> <tag>${project.version}</tag> </configuration> </execution> </executions> <configuration> <!--子用户名@企业别名 或 子用户名@主账号UID--> <username>镜像仓库用户名</username> <!--在容器镜像服务控制台"设置Registry登陆密码"--> <password>镜像仓库密码</password> <!--registry.cn-hangzhou.aliyuncs.com/namespace/repositoryname--> <repository>镜像仓库地址</repository> <tag>latest</tag> <buildArgs> <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration></plugin>
2. 编辑Dockerfile
FROM java:8-jdk-alpine ARG JAR_FILE ADD target/${JAR_FILE} app.jar EXPOSE 8080 ENTRYPOINT ["/usr/bin/java", "-jar", "/app.jar"]
3. 执行构建命令
先查看docker环境变量
$ docker-machine envexport DOCKER_TLS_VERIFY="1"export DOCKER_HOST="tcp://192.168.99.100:2376"export DOCKER_CERT_PATH="C:\Users\shiji\.docker\machine\machines\default"export DOCKER_MACHINE_NAME="default"export COMPOSE_CONVERT_WINDOWS_PATHS="true"
再通过命令行构建
# 不设置环境变量会报错:# Connect to localhost:2375 failed: Connection refusedset DOCKER_HOST=https://192.168.99.100:2376set DOCKER_CERT_PATH=C:\Users\shiji\.docker\machine\machines\default# 生成jar包mvn package -Dmaven.test.skip=true# build imagemvn dockerfile:build# push imagemvn dockerfile:push@tag-version mvn dockerfile:push@tag-latest
作者:核子飞弹
链接:https://www.jianshu.com/p/c0be287ee44e
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦