京东-优惠雷达
无畏Pro 14限量抢购
冷藏饮料节
最高12期免息再送支架
自营热卖

180. docker registry(私有仓库)

风吹向你。 1年前   阅读数 62 0

1. registry部署

0. 导入镜像
[root@docker01 ~]# docker load -i registry.tar.gz

1.启动容器:
[root@docker01 ~]# docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry:latest 

2.上传镜像到私有仓库: [docker02]
a:给镜像打标签 docker tag centos6-sshd:v3 10.0.0.11:5000/centos6-sshd:v3 
b:上传镜像 docker push 10.0.0.11:5000/centos6-sshd:v3

如果遇到报错: 
The push refers to repository [10.0.0.11:5000/centos6.9_ssh] 
Get https://10.0.0.11:5000/v2/: http: server gave HTTP response to HTTPS client

解决方法:
[root@docker02 ~]# vim /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://registry.docker-cn.com"],
  "insecure-registries": ["10.0.0.11:5000"]
}

[root@docker02 ~]# docker push 10.0.0.11:5000/nginx:latest 
The push refers to repository [10.0.0.11:5000/nginx]
e8dc1aeb3107: Pushed 
b5e11aae8a8e: Pushed 
latest: digest: sha256:1f0135c62f2521cbc0426ffad0d8e7e85be116d34cff774ff824bb922171cd0f size: 741

docker01===》启动registry容器---->
[root@docker01 opt]# rm -rf /opt/myregistry/ 清理缓存

docker02===》push镜像到docker01--->前提需要配置/etc/docker/daemon.json
{
  "registry-mirrors": ["https://registry.docker-cn.com"],
  "insecure-registries": ["10.0.0.11:5000"]
}
docker02清理缓存
systemctl stop docker
[root@docker02 docker]# rm -rf /var/lib/docker/*
systemctl restart docker

从内网pull镜像
[root@docker02 ~]# docker pull 10.0.0.11:5000/centos:6.9

2. registry查看镜像

浏览器访问http://10.0.0.11:5000/v2/_catalog
在这里插入图片描述
查看镜像版本:
在这里插入图片描述

删除镜像
1)进入docker registry的容器中
docker exec -it registry /bin/sh

2) 删除repo
rm -fr /var/lib/registry/docker/registry/v2/repositories/nginx

3) 清除掉blob
registry garbage-collect /etc/docker/registry/config.yml

带认证的registry
yum install httpd-tools -y

mkdir /opt/registry-var/auth/ -p

htpasswd -Bbn oldboy 123456 >> /opt/registry-var/auth/htpasswd

docker run -d -p 5000:5000 -v /opt/registry-var/auth/:/auth/ -v /opt/myregistry:/var/lib/registry -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry

提示:上传下载镜像都需要登陆哦

痛点:

  1. 如果要查看所有的镜像和版本,只能一个一个看,不易管理;
  2. 没有安全认证,所有人都可以上传镜像

3. 上传镜像至官方仓库

[root@docker02 ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: chengyinwu
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

[root@docker02 ~]# docker tag centos:6.9 chengyinwu/centos:6.9
[root@docker02 ~]# docker push chengyinwu/centos:6.9
The push refers to repository [docker.io/chengyinwu/centos]
b5e11aae8a8e: Pushing [=>                                                 ]  6.467MB/194.8MB


查看账号:
[root@docker02 ~]# cat /root/.docker/config.json 

发布了184 篇原创文章 · 获赞 72 · 访问量 1万+

注意:本文归作者所有,未经作者允许,不得转载

全部评论: 0

    我有话说: