Skip to content

Latest commit

 

History

History
66 lines (55 loc) · 1.79 KB

docker-registry.md

File metadata and controls

66 lines (55 loc) · 1.79 KB

docker搭建私有仓库

安装docker

可以按照文档安装docker

安装registry仓库

  1. 下载registry镜像
$ docker pull registry
  1. 启动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
  1. 查看仓库
$ docker ps
  1. 验证仓库
$ curl hub.nuoooo.com/v2/_catalog
{"repositories":[]}

仓库使用

  1. 配置

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
  1. 为提交到的镜像添加标签
$ docker tag ubuntu:18.04 hub.nuoooo.com/ubuntu:18.04
  1. 推送到仓库
$ docker push hub.nuoooo.com/ubuntu:18.04

Note

  • 如果仓库使用的是nginx,可能会由于nginx的上传文件大小限制而报错,在nginx配置文件http块或者server块添加client_max_body_size 20m;
  1. 查看仓库
$ ls /opt/registry/docker/registry/v2/repositories
hello-world  ubuntu
  1. 拉取镜像
$ docker pull hub.nuoooo.com/ubuntu:18.04