温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

7.docker-registry私有仓库

发布时间:2020-02-23 01:36:36 来源:网络 阅读:234 作者:Eric_张子豪 栏目:云计算

1.下载私有仓库镜像

[root@docker03 ~]# docker pull registry 
Using default tag: latest
latest: Pulling from library/registry
c87736221ed0: Pull complete 
1cc8e0bb44df: Pull complete 
54d33bcb37f5: Pull complete 
e8afc091c171: Pull complete 
b4541f6d3db6: Pull complete 
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest

2.启动镜像

[root@docker03 ~]# docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
c167a59c546c90e32bd0f15cc9b219555056d89b0f09af61f4b0e0ae8d930a82

3.第一次上传报错

[root@docker03 ~]# docker tag centos:7 10.0.0.13:5000/centos:7

[root@docker03 ~]# docker push 10.0.0.13:5000/centos

The push refers to repository [10.0.0.13:5000/centos]

Get https://10.0.0.13:5000/v2/: http: server gave HTTP response to HTTPS client

4.默认是http,添加信任(文件默认是没有的)

vim /etc/docker/daemon.json
{
  "insecure-registries": ["10.0.0.13:5000"]
}
#重启docker
systemctl  restart docker

5.上传(push)镜像测试

root@docker03 ~]# docker push 10.0.0.13:5000/centos:6.9 
The push refers to repository [10.0.0.13:5000/cnetos]
aaa5621d7c01: Pushed 

6.下载(pull)镜像测试

[root@docker03 ~]# docker pull  10.0.0.13:5000/centos:6.9   

7.删除私有仓库中的镜像

#进入私有仓库registry
[root@docker03 ~]# docker exec -it registry /bin/sh
#删除repo
~ # rm -rf /var/lib/registry/docker/registry/v2/repositories/cnetos
#清楚掉blob
~ # registry garbage-collect /etc/docker/registry/config.yml

8.把registry加认证

[root@docker03 ~]# yum install httpd-tools -y
[root@docker03 ~]# mkdir /opt/registry-var/auth/ -p
[root@docker03 ~]# htpasswd -Bbn shuai 123456 >> /opt/registry-var/auth/htpasswd
[root@docker03 ~]# 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
#没有认证无法上传
[root@docker03 ~]# docker tag centos:latest 10.0.0.13:5000/centos:7           
[root@docker03 ~]# docker push 10.0.0.13:5000/centos:7 
The push refers to repository [10.0.0.13:5000/centos]
9e607bb861a7: Preparing 
no basic auth credentials
#登陆上传
[root@docker03 ~]# docker login 10.0.0.13:5000
Username: shuai    
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@docker03 ~]# docker push 10.0.0.13:5000/centos:7 
The push refers to repository [10.0.0.13:5000/centos]
9e607bb861a7: Pushed 
7: digest: sha256:6ab380c5a5acf71c1b6660d645d2cd79cc8ce91b38e0352cbf9561e050427baf size: 529
#登出
[root@docker03 ~]# docker logout 10.0.0.13:5000
Removing login credentials for 10.0.0.13:5000

9.密码文件目录

[root@docker03 ~]# cat /root/.docker/config.json 
{
    "auths": {
        "10.0.0.13:5000": {
            "auth": "c2h2YWk6MTIzNDU2"
        }
    },
    "HttpHeaders": {
        "User-Agent": "Docker-Client/19.03.3 (linux)"
    }
#使用base64认证c2h2YWk6MTIzNDU2=shuai:123456
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI