因实际项目需要因此创建docker私有库,试过docker registry、harbor,虽然harbor功能强大,可是配置个人认为笔记复杂(python,docker-compose,Harbor等

用两天时间全部配置了一遍,最终选择nexus,除了镜像管理弱点,其他基本没有问题

Nexus3是Sonatype提供的仓库管理平台,Nuexus Repository OSS3能够支持Maven、npm、Docker、YUM、Helm等格式数据的存储和发布;并且能够与Jekins、SonaQube和Eclipse等工具进行集成。Nexus3支持作为宿主和代理存储库的Docker存储库,可以直接将这些存储库暴露给客户端工具;也可以以存储库组的方式暴露给客户端工具,存储库组是合并了多个存储库的内容的存储库,能够通过一个URL将多个存储库暴露给客户端工具,从而便于用户的使用。通过nexus3自建能够有效减少访问获取镜像的时间和对带宽使用,并能够通过自有的镜像仓库共享企业自己的镜像。在本文中,采用Docker方式安装部署Nexus3。
注意:目前的版本有2.x和 3.x ,3.x的支持范围更广,支持ruby和docker。如果单纯的maven私服,建议使用2.x

1.安装

docker pull sonatype/nexus3

2.查看日志

Docker  logs nexus3

3.创建一个目录,用于为Nexus3提供持久化存储。

# mkdir -p /usr/local/docker/data/nexus-data && chown -R 200 /usr/local/docker/data/nexus-data

4.接着,就可以通过sonatype/nexus3镜像启动nexus3的容器化应用了。

 docker run -d -p 8081:8081 -p 8082:8082 -p 8083:8083  -p 8084:8084   --restart=always  --name nexus2 -v /usr/local/docker/data/nexus-data:/nexus-data sonatype/nexus3

8081:可以通过http访问nexus应用

8082:docker(hosted)私有仓库,可以pull和push

8083:docker(proxy)代理远程仓库,只能pull

8084:docker(group)私有仓库和代理的组,只能pull

注意

报错Incorrect username or password, or no permission

1.后来注意到在登陆时有提示信息 ,密码保存在 /nexus-data下的 admin.password  中。

2. 进入容器:docker exec -it 容器id /bin/bash 

意密码只有这一部分:cb424ffc-fc4b-41c1-9cbf-d7ea26efd978,紧跟后面的 bash-4.2$ 不是密码内容。

我也不清楚这里为什么没有自动换行。此密码不是密文,直接登陆时输入就行。

退出容器命令:exit  

5.启动

nexus3搭建docker nexus dock_Docker

6.配置网上很多这三个配置不多说

nexus3搭建docker nexus dock_上传_02

7.修改docker配置

在/etc/docker/daemon.json文件中添加下面的内容:

[root@localhost ~]# cat /etc/docker/daemon.json
{
    "insecure-registries":["192.168.100.163:8082"]
}
[root@master ~]# systemctl daemon-reload
 [root@master ~]# systemctl restart docker
 [root@master ~]# docker info

nexus3搭建docker nexus dock_nexus3搭建docker_03

 

8.首次上传需要验证

[root@master ~]#  docker login 192.168.2.243:8082
 Username: admin
 Password: 
 WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
 Configure a credential helper to remove this warning. See
 https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded


9.上传镜像

[root@master ~]# docker pull hello-world
 Using default tag: latest
 latest: Pulling from library/hello-world
 0e03bdcc26d7: Pull complete 
 Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
 Status: Downloaded newer image for hello-world:latest
 docker.io/library/hello-world:latest
 [root@master ~]# docker tag hello-world 192.168.2.243:8082/helloworld:1.0
 [root@master ~]# docker push 192.168.2.243:8082/helloworld:1.0
 The push refers to repository [192.168.2.243:8082/helloworld]
 9c27e219663c: Pushed 
 1.0: digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 size: 525

10.查看镜像是否上传成功

nexus3搭建docker nexus dock_docker_04

11.下载镜像

[root@master ~]# docker pull 192.168.2.243:8082/helloworld:1.0
 1.0: Pulling from helloworld
 Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
 Status: Image is up to date for 192.168.2.243:8082/helloworld:1.0
 192.168.2.243:8082/helloworld:1.0