以HTTP为例,暂未配置测试HTTPS方式。
存疑问题: 通过代理去公网Pull镜像是否需要配置HTTP代理,安装nexus的机器有访问公网权限,这里未配置HTTP代理。 1、拉取Nexus3版本镜像,启动容器运行私服服务 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201225145337524.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE5MzM3Nzc=,size_16,color_FFFFFF,t_70)
#创建挂载目录,并授权
mkdir -p /opt/nexus/
chown -R 200 /opt/nexus/
#拉取最新nexus3版本的镜像,也可指定版本
docker pull sonatype/nexus3
#启动容器
docker run -d -p 8081:8081 --name nexus --restart always -v /opt/nexus:/nexus-data sonatype/nexus3:latest
注意:这里将nexus容器的数据目录挂载出来,是为了方便修改相关配置后,在需要重建容器时防止配置丢失 2、Web登录Nexus 进行配置 访问地址:http://ip:8081/ 账号密码:admin/admin123(或者查看/opt/nexus/admin.password) 2.1、创建存储空间(可依据需求创建一个或者多个) 2.2、创建仓库 创建私有仓库选择hosted, 创建代理仓库选择proxy, 最后创建一个group类型的仓库用来统一对外提供拉取地址 私有仓库: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201225151227700.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE5MzM3Nzc=,size_16,color_FFFFFF,t_70)
代理仓库: 这里以Hub仓库为例,填写代理仓库名称,选中兼容V1接口,填写Hub仓库地址,选择Docker index,最后选择Blob store即可 ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020122515153580.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE5MzM3Nzc=,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201225151433347.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE5MzM3Nzc=,size_16,color_FFFFFF,t_70)
group仓库 如果需要开启允许匿名拉取镜像,则勾选Allow anonymous docker pull ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201225151941483.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE5MzM3Nzc=,size_16,color_FFFFFF,t_70)
3、 完成配置后,停掉删除nexus容器, 根据镜像重建容器 添加映射端口
docker stop nexus
docker rm nexus
docker run -d -p 8081:8081 -p 8082:8082 -p 8083:8083 --name nexus --restart always -v /opt/nexus:/nexus-data sonatype/nexus3:latest
4、验证服务端口是否正常
curl -I "IP:8081"
curl -I "IP:8082"
curl -I "IP:8083"
8082和8083端口正常页面: 5、客户端(可以找另外一台机器来验证测试)Docker环境变更
vim /etc/docker/daemon.json
{
"data-root": "/opt/docker",
"insecure-registries": ["IP:8082","IP:8083"]
}
systemctl daemon-reload
systemctl restart docker
#验证登录仓库是否正常,这里测试直接使用了admin账户密码
docker login IP:8082
docker login IP:8082
6、验证通过代理拉取Hub官方镜像以及推送镜像到私有仓库
docker pull IP:8082/centos:latest
登录nexus查看验证通过代理拉取镜像 7、本地打包镜像上传到私有仓库
docker tag IP:8082/centos:latest IP:8083/centos:new
docker push IP:8083/centos:new
登录nexus 查看私有仓库 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201225155150710.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE5MzM3Nzc=,size_16,color_FFFFFF,t_70)
|