相思资源网 Design By www.200059.com

一:Docker私有仓库安装

1、 下载镜像是有镜像仓库:

[root@localhost ~]# systemctl start docker

#如果已经有镜像了,强制删除原来的镜像的方式如下:
[root@xxx-pub /]# docker rmi -f docker.io/registry
Untagged: docker.io/registry:latest
Untagged: docker.io/registry@sha256:51bb55f23ef7e25ac9b8313b139a8dd45baa832943c8ad8f7da2ddad6355b3c8
[root@xxx-pub /]#

#开始下载最新的镜像。
[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
4064ffdc82fe: Pull complete 
c12c92d1c5a2: Pull complete 
4fbc9b6835cc: Pull complete 
765973b0f65f: Pull complete 
3968771a7c3a: Pull complete 
Digest: sha256:20bbbc0f6384cf7dc6e292ccbe75935b73c92ec776543c970904bc60feceb129
Status: Downloaded newer image for registry:latest
[root@localhost ~]#

2、 启动并且挂载镜像仓库到本地磁盘:

[root@xxx-pub /]# docker run -d -v /registry:/home/docker-registry -p 5000:5000 --restart=always --privileged=true --name registry registry:latest
Unable to find image 'registry:latest' locally
Trying to pull repository docker.io/library/registry ... 
latest: Pulling from docker.io/library/registry
Digest: sha256:51bb55f23ef7e25ac9b8313b139a8dd45baa832943c8ad8f7da2ddad6355b3c8
Status: Downloaded newer image for docker.io/registry:latest
b7bd2b14ed488936afe798be95f3cd56f604fb092d45cf6f4a58359bcad0d34c
[root@xxx-pub /]#
  • -v /registry:/home/docker-registry:默认情况下,会将仓库存放于容器内的/home/docker-registry目录下,指定本地目录挂载到容器。
  • -p 5000:5000 :端口映射。即本地5000端口,映射到registry中的5000端口。
  • –restart=always1:在容器退出时总是重启容器,主要应用在生产环境。
  • –privileged=true:在CentOS7中的安全模块selinux把权限禁掉了,参数给容器加特权,不加上传镜像会报类似权限错误。OSError: [Errno 13] Permission denied: ‘/tmp/registry/repositories/liibrary')或者(Received unexpected HTTP status: 500 Internal Server Error)
  • –name registry:指定容器的名称。

为了持久化数据,将volume挂载到/home/docker-registry

3、 我们给一个本地镜像打个标签然后上传:

查看本地有哪些镜像:

[root@xxx-pub /]# docker images
REPOSITORY      TAG         IMAGE ID      CREATED       SIZE
docker.io/centos   centos7.5.1804   fdf13fa91c6e    4 weeks ago     200 MB
docker.io/registry  latest       b2b03e9146e1    2 months ago    33.3 MB
[root@xxx-pub /]#

以docker.io/centos为案例。

[root@xxx-pub /]# docker tag fdf13fa91c6e localhost:5000/xxx-centos7.5.1804:1.0
##localhost:5000表示仓库地址,fdf13fa91c6e表示images id,xxx-centos7.5.1804表示镜像名称,1.0表示版本号。

或:
[root@xxx-pub /]# docker tag docker.io/centos:centos7.5.1804 localhost:5000/xxx-centos7.5.1804:1.0

4、 直接上传:

[root@xxx-pub /]# docker push localhost:5000/xxx-centos7.5.1804:1.0
The push refers to a repository [localhost:5000/xxx-centos7.5.1804]
bcc97fbfc9e1: Pushed 
1.0: digest: sha256:7c14180942615fef85cb5c8b1388e028be1a8f79694a5fa30a4025173e42ad61 size: 529
[root@xxx-pub /]#

在PUSH的过程中可能报类似如下的错误(以下是网络上的错误提示):

[root@localhost ~]# docker push 192.168.174.128:5000/hello:latest
The push refers to a repository [192.168.174.128:5000/hello]
unable to ping registry endpoint https://192.168.174.128:5000/v0/
v2 ping attempt failed with error: Get https://192.168.174.128:5000/v2/: http: server gave HTTP response to HTTPS client
 v1 ping attempt failed with error: Get https://192.168.174.128:5000/v1/_ping: http: server gave HTTP response to HTTPS client
[root@localhost ~]#

解决办法:

使用的是https,修改/etc/sysconfig/docker(这里是Centos7下的docker)文件,加上ADD_REGISTRY='–add-registry 192.168.18.162:5000',INSECURE_REGISTRY='–insecure-registry 192.168.18.162:5000' (上面是历史的docker版本的配置),如下图:

Docker私有仓库管理和删除本地仓库中的镜像

但是在新的docker容器仓库的配置中,自己的docker容器中的配置采用(这里在docker registry和另外pull镜像的机器上都指定如下的配置):

Docker私有仓库管理和删除本地仓库中的镜像

指定完成之后,要重启docker,重启的配置如下:

[root@youx-pub volumes]# systemctl restart docker

另外:查看一下docker.service,查看一下配置文件:

[root@youx-pub registry]find / -name docker.service
/sys/fs/cgroup/memory/system.slice/docker.service
/sys/fs/cgroup/devices/system.slice/docker.service
/sys/fs/cgroup/blkio/system.slice/docker.service
/sys/fs/cgroup/cpu,cpuacct/system.slice/docker.service
/sys/fs/cgroup/pids/system.slice/docker.service
/sys/fs/cgroup/systemd/system.slice/docker.service
/usr/lib/systemd/system/docker.service
[root@youx-pub registry]# vim /usr/lib/systemd/system/docker.service

Docker私有仓库管理和删除本地仓库中的镜像 

然后执行一下:

#因为可以用于systemctl启动的docker.service文件变化了,所以得执行以下配置。然后执行docker的重启工作
systemctl daemon-reload
systemctl restart docker

如果还是报如下错误:

[root@youx-pub registry]# docker push 192.168.18.162:5000/nginx:1.2
The push refers to a repository [192.168.18.162:5000/nginx]
Get https://192.168.18.162:5000/v1/_ping: http: server gave HTTP response to HTTPS client
[root@youx-pub registry]#

解决办法是:

在/etc/docker下创建daemon.json,内容是:

{"insecure-registries":["192.168.18.162:5000"]}

然后再重启docker容器:

[root@youx-pub volumes]# systemctl restart docker

5、 上传完成,我们可以查看一下挂载目录是否有镜像:

[root@xxx-pub docker-registry]# pwd
/home/docker-registry
[root@xxx-pub docker-registry] # ls /registry/
Docker

6、 关于本地镜像的查看:

[root@xxx-pub docker-registry]# curl http://192.168.18.162:5000/v2/_catalog
{"repositories":["xxx-centos7.5.1804","xxx-centos7.5.1804-v1.0"]}
[root@xxx-pub docker-registry]#

7、 看到有两个镜像,我们要获取他的标签信息以便下载呢:

[root@xxx-pub docker-registry]# curl http://192.168.18.162:5000/v2/xxx-centos7.5.1804/tags/list
{"name":"xxx-centos7.5.1804","tags":["1.0"]}
[root@xxx-pub docker-registry]#

8、 然后我们直接下载镜像(到另电脑上):

[root@bigdata2 ~]# docker pull 192.168.18.162:5000/youx-centos7.5.1804:1.0
Using default tag: latest
Trying to pull repository 192.168.18.162/youx-centos7.5.1804 ... 
Get https://192.168.18.162/v1/_ping: dial tcp 192.168.18.162:443: getsockopt: no route to host
[root@bigdata2 ~]#

如果出现上面的情况,解决办法是:

编译:

[root@youx-pub volumes]# vim /etc/containers/registries.conf 这个文件。
旧的是编辑:/etc/sysconfig/docker 这个文件

Docker私有仓库管理和删除本地仓库中的镜像 

然后重启docker

[root@youx-pub volumes]# systemctl restart docker

然后发现可以pull了

#要注意的是,这里的地址是:仓库地址:仓库端口号/REPOSITORY:TAG
[root@bigdata2 ~]# docker pull 192.168.18.162:5000/youx-centos7.5.1804:1.0

Docker私有仓库管理和删除本地仓库中的镜像

如果还不行,需要修改/etc/docker/daemon.json,内容如下:

[root@bigdata2 docker]# cat daemon.json 
{"insecure-registries":["192.168.18.162:5000"]}

二、从另外一台机器上上传镜像到docker镜像仓库:

[root@bigdata2 ~]# docker tag centos7-jdk8-nginx:1.0 192.168.18.162:5000/centos7-jdk8-nginx:1.0
[root@bigdata2 ~]# docker images
REPOSITORY                TAG         IMAGE ID      CREATED       SIZE
192.168.18.162:5000/centos7-jdk8-nginx  1.0         bcacd65e2a2e    2 minutes ago    2.18 GB

[root@bigdata2 ~]# docker push 192.168.18.162:5000/centos7-jdk8-nginx:1.0
The push refers to a repository [192.168.18.162:5000/centos7-jdk8-nginx]
f018e9c38a66: Pushed 
2a47dcd341ef: Pushed 
c5dea3bc729a: Pushed 
bcc97fbfc9e1: Pushed 
1.0: digest: sha256:d907ff2f8eb590209700c01ce85c78d0bc778a4238539d747e4667d68cb52102 size: 1163
[root@bigdata2 ~]#

然后进入docker镜像仓库所在位置:

[root@youx-pub registry]# curl http://192.168.18.162:5000/v2/_catalog
{"repositories":["centos7-jdk8-nginx","nginx"]}
[root@youx-pub registry]# curl http://192.168.18.162:5000/v2/centos7-jdk8-nginx/tags/list
{"name":"centos7-jdk8-nginx","tags":["1.0"]}
[root@youx-pub registry]#

三、本地镜像如何删除,正常是不提供删除功能的,所以使用第三方的插件来进行删除

插件github上的位置:
https://github.com/burnettk/delete-docker-registry-image

1、下载资源

[root@master registry]# curl https://raw.githubusercontent.com/burnettk/delete-docker-registry-image/master/delete_docker_registry_image.py | sudo tee /usr/local/bin/delete_docker_registry_image >/dev/null

sudo chmod a+x /usr/local/bin/delete_docker_registry_image 

Docker私有仓库管理和删除本地仓库中的镜像

2、 设置相关环节变量:

查找REGISTRY_DATA_DIR,命令:
[root@youx-pub registry]# find / -name registry
[root@youx-pub registry]# find / -name registry
/var/lib/docker/overlay2/d72320cd67b42f7ae66342cc6dedab7abe5e89106de8c4919ec8c5a6e5940b09/diff/var/lib/ucf/registry
/var/lib/docker/overlay2/92211417089f7be8239def550e1e89ce3f0e50ac57f2c36ba723ca312ea06ae3/diff/bin/registry
/var/lib/docker/overlay2/c1716aea0b380eb94ead9aa02552769acd4c3dac8e6dab735997f1709ce79a33/diff/etc/docker/registry
/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/diff/var/lib/registry
/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/bin/registry
/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/etc/docker/registry
/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/var/lib/registry
/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry
/opt/data/registry
/registry
[root@youx-pub registry]#
发现
[root@youx-pub repositories]# pwd
/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry/v2/repositories
[root@youx-pub repositories]# ls
centos7-jdk8-nginx nginx
[root@youx-pub repositories]#

所以设置镜像仓库的位置为:
[root@master registry]# export REGISTRY_DATA_DIR=/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry/v2

地址就是咱们挂载地址:

看一下相关标签:

[root@youx-pub registry]# curl http://192.168.18.162:5000/v2/_catalog
{"repositories":["youx-centos7.5.1804","youx-centos7.5.1804-v1.0"]}
[root@youx-pub registry]# curl http://192.168.18.162:5000/v2/youx-centos7.5.1804-v1.0/tags/list
{"name":"youx-centos7.5.1804-v1.0","tags":["latest"]}
[root@youx-pub registry]#

可以之后我们直接删除:

[root@master registry]# delete_docker_registry_image --image youx-centos7.5.1804-v1.0:latest

INFO [2017-04-08 11:39:39,793] Deleting /registry/docker/registry/v2/repositories/nginx/_manifests/tags/v1
咱们再看一下本地仓库的镜像有几个:

[root@master registry]# curl http://192.168.18.162:5000/v2/_catalog
{"repositories":["youx-centos7.5.1804"]}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
Docker,私有仓库管理,Docker,私有仓库,Docker,删除仓库镜像

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“Docker私有仓库管理和删除本地仓库中的镜像”

暂无Docker私有仓库管理和删除本地仓库中的镜像的评论...