使用Maven插件构建Docker镜像并上传

工具

插件名称 官方地址
docker-maven-plugin https://github.com/spotify/docker-maven-plugin

在pom.xml中添加下面这段(Dockerfile构建)



    com.spotify
    docker-maven-plugin
    1.1.1
    
        
        ${project.basedir}
        
        registry.cn-shanghai.aliyuncs.com/ycmm/${project.artifactId}:${project.version}
        
        true
        
            ${project.version}
        
        
        
            
                /
                ${project.build.directory}
                ${project.build.finalName}.jar
            
        
        
        docker-ali
        registry.cn-shanghai.aliyuncs.com
    

构建命令

mvn clean package docker:build

将插件绑定在某个phase执行

  • mvn install 时能够docker:build
  • mvn deploy 时能够docker:push

我们只需要将插件的goal 绑定在某个phase即可。

所谓的phase和goal,可以这样理解:maven命令格式是:mvn phase:goal ,例如mvn package docker:build 那么,package 和docker 都是phase,build 则是goal 。

修改POM文件


    com.spotify
    docker-maven-plugin
    1.1.1
    
        
            build-image
            package
            
                build
            
        
        
            push-image
            deploy
            
                push
            
            
                ${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
            
           
    
    
        
        ${project.basedir}
        
        registry.cn-shanghai.aliyuncs.com/ycmm/${project.artifactId}:${project.version}
        
        
        
        
            
                /
                ${project.build.directory}
                ${project.build.finalName}.jar
            
        
        
        docker-ali
        registry.cn-shanghai.aliyuncs.com
    

你可能感兴趣的:(Docker)