Maven+Docker,发布到Registry
1、配置Pom.xml
1 2 3 4 5 | < properties > < project.build.sourceEncoding >UTF-8</ project.build.sourceEncoding > < docker.repostory >registry.cn-hangzhou.aliyuncs.com</ docker.repostory > < docker.registry.name >kingsy</ docker.registry.name > </ properties > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | < build > < finalName >app</ finalName > < plugins > <!-- 生成Jar包 --> < plugin > < groupId >org.apache.maven.plugins</ groupId > < artifactId >maven-jar-plugin</ artifactId > < version >2.4</ version > < configuration > < archive > < manifest > < addClasspath >true</ addClasspath > < classpathPrefix >lib/</ classpathPrefix > < mainClass >org.demo.docker_package.App</ mainClass > </ manifest > </ archive > </ configuration > </ plugin > <!-- 打包Docker --> < plugin > < groupId >com.spotify</ groupId > < artifactId >docker-maven-plugin</ artifactId > < version >0.4.13</ version > < executions > < execution > < id >build-image</ id > < phase >package</ phase > < goals > < goal >build</ goal > </ goals > </ execution > < execution > < id >tag-image</ id > < phase >package</ phase > < goals > < goal >tag</ goal > </ goals > < configuration > < image >${docker.registry.name}/${project.artifactId}:${project.version}</ image > < newName >${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}</ newName > </ configuration > </ execution > < execution > < id >push-image</ id > < phase >deploy</ phase > < goals > < goal >push</ goal > </ goals > < configuration > < imageName >${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}</ imageName > </ configuration > </ execution > </ executions > < configuration > < serverId >docker-aliyun</ serverId > < registryUrl >registry.cn-hangzhou.aliyuncs.com</ registryUrl > < pushImage >true</ pushImage > < dockerDirectory >${project.basedir}</ dockerDirectory > < imageName >${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}</ imageName > < imageTags > < imageTag >latest</ imageTag > </ imageTags > < resources > < resource > < targetPath >/</ targetPath > < directory >${project.build.directory}</ directory > < include >${project.build.finalName}.jar</ include > </ resource > </ resources > </ configuration > </ plugin > </ plugins > </ build > |
二、创建Dockerfile
1 2 3 4 | FROM java:7 ADD target/app.jar /home WORKDIR /home ENTRYPOINT ["java","-jar","app.jar"] |
三、修改~/.m2/settings.xml
1 2 3 4 5 6 7 8 9 10 | < settings > < server > < id >docker-aliyun</ id > < username >kingsylin@vip.qq.com</ username > < password >密码</ password > < configuration > < email >kingsylin@vip.qq.com</ email > </ configuration > </ server > </ settings > |
四、执行maven命令
1 | clean install |