在前两篇文章2.Docker-resigtry2和3.SpringCloud-Eureka-Docker基础上进行配置。
例子使用com.spotify的maven插件,后续会对比研究io.fabric3的maven插件。
1.将插件配置到pom文件中
1.1 定义变量
配置hosts文件,加入59.110.14.120 docker.registry.server
docker.registry.server:5000
1.2 配置插件
com.spotify
docker-maven-plugin
3.7.0
docker.registry.server
${docker.registry.server}/${project.artifactId}
openjdk:8u131-jdk-alpine
["java", "-jar", "/${project.build.finalName}.jar"]
/
${project.build.directory}
${project.build.finalName}.jar
build-image
package
build
tag-image
package
tag
${docker.registry.server}/${project.artifactId}
${docker.registry.server}/${project.artifactId}
1.3 setting.xml配置
docker.registry.server
gaojingyuan
testpwd
[email protected]
2.打包并推送image
mvn clean package -DpushImage
3. 服务器下载并启动服务
登录私服
docker login docker.registry.server:5000
下载镜像
docker pull docker.registry.server:5000/eurekaserverdocker
启动服务
docker stack deploy -c docker-compose.yml eurekaserverdocker
停止服务
docker stack rm eurekaserverdocker
常见错误:
1.执行mvn clean package -DpushImage5次retry后报错:
Failed to push docker.registry.server:5000/eurekaserverdocker, retrying in 10 seconds (5/5).
com.spotify.docker.client.exceptions.DockerException: no basic auth credentials
解决方法:
需要配置 vim .docker/config.json
把"docker.registry.server:5000": {},改为"https://docker.registry.server:5000": {},
"auths": {
"https://docker.registry.server:5000": {},
"https://index.docker.io/v1/": {}
},
https://github.com/spotify/docker-client/issues/804
2.执行mvn clean package -DpushImage报错:
Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:tag (tag-image) on project eurekaserverdocker: Exception caught: Image not found: eurekaserverdocker: Request error: POST unix://localhost:80/images/eurekaserverdocker/tag?repo=docker.registry.server%3A5000%2Feurekaserverdocker: 404, body: {"message":"No such image: eurekaserverdocker:latest"}: HTTP 404 Not Found -> [Help 1]
解决方法:
需要正确配置
tag-image
package
tag
${docker.registry.server}/${project.artifactId}
${docker.registry.server}/${project.artifactId}
参考
https://github.com/spotify/docker-maven-plugin
https://www.jianshu.com/p/3b91b8958c3e