使用Maven来构建Docker镜像并上传到私服仓库

准备工作

开启远程端口
docker服务器上
1.直接在公有仓库拉取仓库的镜像

docker pull registry

2.修改docker配置

vim   /usr/lib/systemd/system/docker.service

ExecStart 添加 -H tcp://0.0.0.0:2375
添加后如下

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --insecure-registry 0.0.0.0:5000  -H tcp://0.0.0.0:2375  -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

重新加载配置文件重启

systemctl daemon-reload
systemctl restart docker

maven配置:
无需yml的pom.xml配置

 
        
            
                com.spotify
                docker-maven-plugin
                0.4.13
                
                   true    
                    my/eureka:0.0.1  
                    lwieske/java-8    
                    http://192.168.10.72:2375  
                    ["java","-jar","/${project.build.finalName}.jar"] 
                    
                                                                     
                            /                         
                            ${project.build.directory}  
                            ${project.build.finalName}.jar  
                        
                    
                
            
        
    

需要yml的pom文件配置


                com.spotify
                docker-maven-plugin
                0.4.13
                
                    true    
                    my/eureka:0.0.2  
                    http://192.168.10.73:2375  
                    ${project.basedir}/src/main/docker   
                    
                                                                     
                            /                         
                            ${project.build.directory}  
                            ${project.build.finalName}.jar  
                        
                    
                
            

maven 发布
重点!!!!
镜像名称一定不能有大写字母
因为镜像名称取的是项目名称,而项目名称有大写英文字母导致镜像一直上传失败提示:Broken pipe (Write failed)
在maven中配置名称小写就上传成功了

clean package  docker:build

你可能感兴趣的:(使用Maven来构建Docker镜像并上传到私服仓库)