docker通过nexus3打包上传镜像部署

docker通过nexus3打包上传镜像部署

查询nexus镜像

查看镜像:https://hub.docker.com/r/sonatype/nexus3
docker通过nexus3打包上传镜像部署
查询镜像:
docker search nexus
docker通过nexus3打包上传镜像部署

获取nexus3镜像

docker pull sonatype/nexus3
docker images
docker通过nexus3打包上传镜像部署

创建挂载目录:

mkdir -p /home/data/nexus/nexus-data
chmod 777 -R /home/data
docker通过nexus3打包上传镜像部署

启动nexus3容器

docker run -d -p 8081:8081 -p 8085:8085 -p 8086:8086 --name nexus3 -v /home/data/nexus/nexus-data:/nexus-data --restart=always sonatype/nexus3:latest
参数说明:
8081端口是nexus3的服务端口
8085端口用于host镜像仓库的服务端口
8086端口用于group镜像仓库的服务端口
-v /home/data/nexus/nexus-data:/nexus-data 将容器内nexus-data 数据文件夹挂载到宿主机/home/data/nexus/nexus-data目录下
–restart=always 不管退出的状态码是什么,在重启docker时,都将重启容器。
docker通过nexus3打包上传镜像部署
启动后稍等几分钟,服务在后台启动需要一点时间,可以通过查看日志是否启动完成。
docker logs 8a0c6a299f2a
docker通过nexus3打包上传镜像部署
查看日志如果有started sonatype nexus oss 3.31.0-01信息,表示以上nexus启动完成,接下来,通过网页访问nexus修改登录密码,创建仓库等。

查看登录密码:
启动成功后,通过 exec 命令对指定的容器执行 bash,查看 admin的密码
docker exec -it 8a0c6a299f2a /bin/bash
vi /nexus-data/admin.password
docker通过nexus3打包上传镜像部署
可以看到密码是一串字符串,首次登录是使用admin 账号和该密码登录即可。

创建docker私有仓库

登录设置密码

通过浏览器访问nexus3: http://192.168.0.85:8081/#browse/browse, 登录账号默认admin,密码是以上查看admin.password的字符串。
docker通过nexus3打包上传镜像部署
点击sigin in后如下:
docker通过nexus3打包上传镜像部署
首次登录需要设置新的登录密码,我这里设置为:admin123
docker通过nexus3打包上传镜像部署
这里勾选禁用匿名账号登录。
docker通过nexus3打包上传镜像部署
docker通过nexus3打包上传镜像部署
docker通过nexus3打包上传镜像部署
登录完成如下:
可以看到,登录完成后,多了一个设置按钮。
docker通过nexus3打包上传镜像部署
默认仓库说明:
maven-central:maven *库,默认从 https://repo1.maven.org/maven2/ 拉取 jar
maven-releases:私库发行版 jar,初次安装请将 Deployment policy 设置为 Allow redeploy
maven-snapshots:私库快照(调试版本)jar
maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地 maven 基础配置 settings.xml 或项目 pom.xml 中使用

仓库类型说明:
group:这是一个仓库聚合的概念,用户仓库地址选择 Group 的地址,即可访问 Group 中配置的,用于方便开发人员自己设定的仓库。
maven-public 就是一个 Group 类型的仓库,内部设置了多个仓库,访问顺序取决于配置顺序,3.x 默认为 Releases、Snapshots、Central,当然你也可以自己设置。
hosted:私有仓库,内部项目的发布仓库,专门用来存储我们自己生成的 jar 文件
snapshots:本地项目的快照仓库
releases: 本地项目发布的正式版本
proxy:代理类型,从远程*仓库中寻找数据的仓库(可以点击对应的仓库的 Configuration 页签下, Remote Storage 属性的值即被代理的远程仓库的路径),如可配置阿里云 maven 仓库
central:*仓库

创建hosted仓库(8085)

点击repository->create repository.
docker通过nexus3打包上传镜像部署
选择docker hosted 本地私服功能创建
docker通过nexus3打包上传镜像部署
指定docker仓库名称、指定一个端口8085来通过http的方式访问仓库、勾选是否支持docker API VI,然后点击create repository 按钮创建hosted仓库。
docker通过nexus3打包上传镜像部署
一、国内仓库
DaoCloud 道客网络: https://hub.daocloud.io/
Docker-CN: https://registry.docker-cn.com
中科大镜像: https://docker.mirrors.ustc.edu.cn
Azure中国镜像: https://dockerhub.azk8s.cn
二、国外仓库
Docker Hub: https://hub.docker.com/
Quay: https://quay.io/search
{
“registry-mirrors”: [
“https://dockerhub.azk8s.cn”,
“https://docker.mirrors.ustc.edu.cn”,
“https://registry.docker-cn.com”
]
}

创建proxy仓库(8081)

docker通过nexus3打包上传镜像部署
docker通过nexus3打包上传镜像部署
录入proxy仓库名称,端口,镜像地址,然后在 Remote storage中输入需要代理的镜像仓库地址,这里我们选用中国境内的仓库https://registry.docker-cn.com ,Docker Index 选择Use Docker Hub,保存即可。

创建group仓库(8086)

docker通过nexus3打包上传镜像部署
docker通过nexus3打包上传镜像部署
docker通过nexus3打包上传镜像部署
docker通过nexus3打包上传镜像部署
录入group组名称,然后录入http端口号 8086,在Member repositories 中将 hosted 和proxy 从左左边移到右边,同时保证hosted在前,这样才能在拉取镜像的时候首先从本地拉取,如果拉取不到才从*仓库(远程)拉取。

设置Realms

将 Docker Bearer Toker Realm从左边窗口移动到右边窗口,然后保存
docker通过nexus3打包上传镜像部署
docker通过nexus3打包上传镜像部署

docker服务设置

开启docker远程调用

开启docker远程调用配置:
vim /usr/lib/systemd/system/docker.service
在 ExecStart 追加:-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
如下:

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

docker通过nexus3打包上传镜像部署
重启docker
systemctl daemon-reload
systemclt restart docker

添加http访问

由于我们使用的时http而不是https ,故需要在启动参数文件中设置,将vi /etc/docker/daemon.json,将ip:8085(hosted)和ip:8086(group) 添加到 insecure-registries 参数中,由于我们的远程仓库地址为https://registry.docker-cn.com,不为https 故同样需要将该地址添加到insecure-registries参数中:“insecure-registries”:[“ip:8082”,“ip:8083”,“https://registry.docker-cn.com”]
内容如下:

vi /etc/docker/daemon.json
{
  "insecure-registries":[
    "192.168.0.85:8081",
    "192.168.0.85:8085",
    "192.168.0.85:8086",
    "120.79.51.144:8079"
  ]
}
{
  "registry-mirrors": [
    "https://registry.docker-cn.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://hub-mirror.c.163.com",
    "https://hub.docker.com",
    "https://hub.daocloud.io"
  ]
}

docker通过nexus3打包上传镜像部署
重启docker
systemctl daemon-reload
systemctl restart docker

登录验证

docker login ip:8085
docker login ip:8086
8085(hosted)和8086(group),在登录需要输入登录用户名及密码,即为你的nexus3的登录用户名及密码
docker通过nexus3打包上传镜像部署

验证hosted(8085)
tag镜像:docker tag nginx:latest ip:8082/nginx:latest
登录服务:
docker login 192.168.0.85:8085
docker通过nexus3打包上传镜像部署
生成镜像:
docker tag e12d72fd1857 192.168.0.85:8085/mongo:latest
docker通过nexus3打包上传镜像部署
push 镜像:docker push ip:8082/nginx:latest
上传镜像到nexus:
docker通过nexus3打包上传镜像部署
登录nexus网页查看上传镜像:
docker通过nexus3打包上传镜像部署

docker安装错误

Error response from daemon: Get https://192.168.0.85:8085/v2/: http: server gave HTTP response to HTTPS client

docker通过nexus3打包上传镜像部署
以上问题主要是安装nexus是使用http协议导致,需要在配置文件中增加nexus访问地址即可。
vi /etc/docker/daemon.json内容如下:
{
“insecure-registries”:[
“192.168.0.85:8085”,
“192.168.0.85:8086”,
“http://hub-mirror.c.163.com”
]
}
{
“registry-mirrors”: [
“https://dockerhub.azk8s.cn”,
“https://docker.mirrors.ustc.edu.cn”,
“https://registry.docker-cn.com”
]
}
添加完成后,重启docker服务即可
systemctl daemon-reload
systemctl restart docker

manifest unknown

Error response from daemon: manifest for 192.168.0.85:8086/redis:latest not found: manifest unknown: manifest unknown
docker通过nexus3打包上传镜像部署
主要原因是私有仓库没有该镜像,导致,可以使用docker pull redis:latest到公网镜像拉取。

在拉取镜像的时候报错Client.Timeout exceeded while awaiting headers

docker通过nexus3打包上传镜像部署
原因:延迟较大,网络连接出现问题
该脚本可以将 --registry-mirror 加入到你的 Docker 配置文件,在/etc/docker/daemon.json文件添加上如下配置:
docker通过nexus3打包上传镜像部署
加载配置文件、重启docker
$systemctl daemon-reload
$systemctl restart docker

上一篇:右侧maven只有lifecycle解决方法


下一篇:【工作经验】项目打成的Jar包推送到公司私服nexus