构建私有Docker Registry

 

1.设置insecure-registry:git

可能会出现没法push镜像到私有仓库的问题。github

这是由于咱们启动的registry服务不是安全可信赖的。docker

1) sudo vim /etc/default/docker 
DOCKER_OPTS="--insecure-registry 10.229.43.237:5000" vim

2) $ sudo service docker restart浏览器

 

2.获取registry镜像 安全

Registry之前是用Python写的,考虑到效率问题,spa

后来用Go重写一遍,因此github看到的是distribution。rest

https://github.com/docker/distributionblog

$ sudo docker pull registry:2.5.1it

 

3.启动registry容器

$ sudo docker run -d -v /opt/registry:/var/lib/registry -p 10000:5000 --restart=always --name registry registry:2.5.1

$ netstat -an | grep 5000 检查5000端口是否被占用。

Registry服务默认会将上传的镜像保存在容器的/var/lib/registry,

咱们将主机的/opt/registry目录挂载到该目录,便可实现将镜像保存到主机的/opt/registry目录。

打开浏览器输入http://127.0.0.1:10000/v2,能够访问说明registry运行正常。

 

4.Tag镜像

$ sudo docker tag hello-world 127.0.0.1:10000/hello-world

$ sudo docker images 能够看到新产生了一个本地镜像127.0.0.1:10000/hello-world

 

5.推送本地镜像到私有Registry

$ sudo docker push 127.0.0.1:10000/hello-world

打开浏览器输入http://127.0.0.1:10000/v2/_catalog,检查registry是否包含hello-world

 

6.删除本地镜像

$ sudo docker rmi 127.0.0.1:10000/hello-world

 

7.从新拉取镜像

$ sudo docker pull 127.0.0.1:10000/hello-world

$ sudo docker run 127.0.0.1:10000/hello-world

相关文章
相关标签/搜索