可以按照文档安装
docker
- 下载
registry
镜像
$ docker pull registry
- 启动
registry
# -d 以服务运行
# -p 端口映射
# --restart 在容器退出时总是重启容器,主要应用在生产环境
# -v 默认情况下,会将仓库存放于容器内的/var/lib/registry目录下,指定本地目录挂载到容器
$ docker run -d -p 5000:5000 --name registry --restart=always -v /opt/registry:/var/lib/registry registry:latest
- 查看仓库
$ docker ps
- 验证仓库
$ curl hub.nuoooo.com/v2/_catalog
{"repositories":[]}
- 配置
dockers registry V2
版本客户端默认使用https
协议去push
镜像到仓库服务器,而现在我们的仓库服务器只配置了支持http
,所以客户端会push
镜像失败。如要希望docker
客户端支持http
协议,需在启动docker
时加入参数--insecure-registry your_registry_ip:port
在/usr/lib/systemd/system/docker.service
中添加--insecure-registry hub.nuoooo.com
ExecStart=/usr/bin/dockerd -H unix:// --insecure-registry hub.nuoooo.com
ExecReload=/bin/kill -s HUP $MAINPID
- 为提交到的镜像添加标签
$ docker tag ubuntu:18.04 hub.nuoooo.com/ubuntu:18.04
- 推送到仓库
$ docker push hub.nuoooo.com/ubuntu:18.04
Note
- 如果仓库使用的是
nginx
,可能会由于nginx
的上传文件大小限制而报错,在nginx
配置文件http
块或者server
块添加client_max_body_size 20m;
- 查看仓库
$ ls /opt/registry/docker/registry/v2/repositories
hello-world ubuntu
- 拉取镜像
$ docker pull hub.nuoooo.com/ubuntu:18.04