spring-boot 构建上传到nexus私服

2021-03-18  本文已影响0人  林亚希

新项目构建自动化docker部署第一步

1. 将打包的docker镜像包发布到nexus私服上

需要准备

  1. nexus3
  2. docker
  3. maven
    上述安装就不涉及了,直接进入主题

2. nexus上配置docker仓库

由于我们使用的时http而不是https 故需要在启动参数文件中设置
vi /etc/docker/daemon.json,将ip:8082和ip:8083 添加到 insecure-registries 参数中,由于我们的远程仓库地址为http://hub-mirror.c.163.com,不为https 故同样需要将该地址添加到insecure-registries参数中:"insecure-registries":["ip:8082","ip:8083","http://hub-mirror.c.163.com"]
重启docker
systemctl daemon-reload
systemctl restart docker

3. 验证

docker login ip:8082
docker login ip:8083
在登录需要输入登录用户名及密码,即为你的nexus3的登录用户名及密码
验证proxy
docker pull ip:8083/redis
此docker私服仓库中时没有redis的镜像的,故nexus3会从中央仓库中去拉取镜像,拉取成功之后,查看nexus3的proxy仓库发现已经存在了redis镜像
验证hosted
tag镜像:docker tag nginx:latest ip:8082/nginx:latest
push 镜像:docker push ip:8082/nginx:latest
此时查看hosted仓库发现已经存nginx的镜像了

4. 使用maven打包docker镜像并推送到nexus3

<plugin>
               <groupId>com.spotify</groupId>
               <artifactId>docker-maven-plugin</artifactId>
               <version>${docker.plugin.version}</version>
               <configuration>
                   <imageName>${docker.registry.url}:8083/bull3d/${project.artifactId}:${project.version}</imageName>
                   <dockerDirectory>${project.basedir}</dockerDirectory>
                   <serverId>docker-hub</serverId>
                   <dockerHost>${docker.registry.host}</dockerHost>
                   <resources>
                       <resource>
                           <targetPath>/</targetPath>
                           <directory>${project.build.directory}</directory>
                           <include>${project.build.finalName}.jar</include>
                       </resource>
                   </resources>
                   <registryUrl>${docker.registry.url}:8083</registryUrl>
<!--                    <serverId>${docker.registry.url}</serverId>-->
                   <pushImage>true</pushImage>
               </configuration>
           </plugin>
        <server>
            <id>docker-hub</id>
            <username>admin</username>
            <password>123456</password>
        </server>
在<pluginGroups>节点中添加
<pluginGroup>com.spotify</pluginGroup>
  1. vim /usr/lib/systemd/system/docker.service
    在 ExecStart 追加:-H tcp://0.0.0.0:2375
    如:ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H fd:// --containerd=/run/containerd/containerd.sock
  2. 重启docker
    systemctl daemon-reload
    systemclt restart docker
上一篇 下一篇

猜你喜欢

热点阅读