使用 Docker 官方的 Registry 建立的仓库,面临着这样的问题,好比删除镜像后空间默认不会回收,形成空间被占用。比较常见的作法是使用 Nexus 来管理企业的工具包。前端
Nexus 不只能够建立 Docker 仓库,也能够 NPM、Maven 等多种类型的仓库。docker
$ docker run -d --name nexus3 --restart=always \
-p 8081:8081 \
-p 8082:8082 \
--mount src=nexus-data,target=/nexus-data \
sonatype/nexus3
Unable to find image 'sonatype/nexus3:latest' locally
latest: Pulling from sonatype/nexus3
c65691897a4d: Pull complete
641d7cc5cbc4: Pull complete
c508b13320cd: Pull complete
79e3bf9d3132: Pull complete
Digest: sha256:2c33632ccd8f8c5f9023a3d7f5f541e271833e402219f8c5a83a29d1721457ca
Status: Downloaded newer image for sonatype/nexus3:latest
f637e039214978f8aac41e621e51588bd8cd8438055498c4060fbaf87799e64f
复制代码
其中 8081 为 Nexus 的访问端口,8082 为仓库的端口,网上大部分文章并无加上 8082 端口的映射,致使我在测试的时候卡了好久。浏览器
稍等一两分钟,浏览器打开 domain:8081
。bash
点击右上角 Sign in
进行登陆,初始帐号为 admin
,密码能够经过 exec
命令进入容器内,根据提示的路径查看初始密码。dom
进入容器查看初始密码工具
$ docker exec -it f637 /bin/bash
bash-4.4$ vi /nexus-data/admin.password
复制代码
登录后会被要求修改密码,之后将使用这密码。测试
点击导航的齿轮按钮进入设置页面,进入 Repository->Repositories
点击 Create repository
选择 docker (hosted)
ui
docker (hosted)
为本地仓库,docker (proxy)
为代理仓库,docker (group)
为聚合仓库,本文只介绍本地仓库,若是有兴趣也能够到网上查找另外两种仓库的用法。spa
只须要填好上图中红框的部分便可,其中 Name
为仓库名,HTTP
的输入框则是填写端口号 8082,写好以后滑到页面底部,点击 Create repository
即建立仓库。3d
菜单 Security->Realms 把 Docker Bearer Token Realm 移到右边的框中保存。
添加用户规则:菜单 Security->Roles->Create role 在 Privlleges 选项搜索 docker 把相应的规则移动到右边的框中而后保存。
添加用户:菜单 Security->Users->Create local user 在 Roles 选项中选中刚才建立的规则移动到右边的窗口保存。
由于是建立的仓库是用 HTTP 的方式访问的,因此在登陆前须要修改 Docker 配置中的 Daemon
{ "insecure-registries": ["domain:8082"] }
$ docker login domain:8082
Username: yourName
Password:
Login Succeeded
复制代码
上传仓库、下载仓库、搜索仓库 这些内容与上一篇文章中的一致,这里就再也不赘述了。
其中须要注意的点为启动 Nexus 时,须要把仓库的端口一块儿映射到宿主机中。
若是你喜欢个人文章,但愿能够关注一下个人公众号【前端develop】