docker注册中心
作者:互联网
docker hub镜像上传
#1.修改镜像镜像加速器
[root@sunrui ~]# cd /etc/docker/
[root@sunrui docker]# vi daemon.json
{ "registry-mirrors":
["https://registry.docker-cn.com"]
}
[root@sunrui docker]# systemctl daemon-reload
[root@sunrui docker]# systemctl restart docker
#2.登录docker hub官网注册账号:https://hub.docker.com/signup
#3.登录账户,创建一个仓库 # “Create Repository”——》输入命名空间和仓库名——》“Description”填写描述信息——》“visibility”中选择是创建public仓库还是private仓库——》点击“Create”创建仓库
#4.登录Docker Hub
[root@sunrui ~]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you dont have a Docker ID, head over to https://hub.docker.com to create one.
Username: sunrui12138 # 输入创建的用户名
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
#5.构建镜像
[root@sunrui ~]# docker build -t sunrui12138/testdocker .
Sending build context to Docker daemon 865.3kB
Step 1/3 : FROM scratch
--->
Step 2/3 : COPY hello /
---> 2322533b4210
Step 3/3 : CMD ["/hello"]
---> Running in 5994e2099b8d
Removing intermediate container 5994e2099b8d
---> 32fedb0d83ba
Successfully built 32fedb0d83ba
Successfully tagged sunrui12138/testdocker:latest
#6.为已存在的镜像重新设置标签
[root@sunrui ~]# docker tag 32fedb0d83ba sunrui12138/testdocker:22.03
[root@sunrui ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sunrui12138/testdocker 22.03 32fedb0d83ba About a minute ago 861kB
sunrui12138/testdocker latest 32fedb0d83ba About a minute ago 861kB
#7.推送镜像
[root@sunrui ~]# docker push sunrui12138/testdocker:22.03
The push refers to repository [docker.io/sunrui2138/testdocker]
88dc11111fec: Pushed
22.03: digest: sha256:c9225ad48cb94c8f160e839187e81ce28f85dbff8316e7443879f5169f41cfb0 size: 527
#8.在docker hub上检查推送的仓库
[仓库地址](https://hub.docker.com/repository/docker/sunrui12138/testdocker)
docker容器生成镜像提交给hub
#1.登录官网账户,创建一个仓库
# “Create Repository”——》输入命名空间和仓库名——》“Description”填写描述信息——》“visibility”中选择是创建public仓库还是private仓库——》点击“Create”创建仓库
#2.容器提交生成镜像
[root@sunrui ~]# docker commit 4decee095428 sunrui12138/ubuntu:22.03
sha256:a4b85b3fb73e23e75440430252477b77aee8927fdf9495160297b86dcf5f917c
[root@sunrui ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sunrui12138/ubuntu 22.03 a4b85b3fb73e 6 seconds ago 72.8MB
#3.推送镜像
[root@sunrui ~]# docker push sunrui12138/ubuntu:22.03
The push refers to repository [docker.io/sunrui12138/ubuntu]
b954f8dfd459: Pushed
9f54eef41275: Mounted from library/ubuntu
22.03: digest: sha256:573bc189eba09934db466a2344edee5f46cd7d98fb765690b4ba7b1e9dd26624 size: 736
# 4.在docker hub上检查推送的仓库
[仓库地址](https://hub.docker.com/repository/docker/sunrui12138/ubuntu)
docker注册中心
#1.登录aliyun平台,注册登录
[阿里云官网地址](https://www.aliyun.com)
#2.在阿里云控制台创建仓库
# 打开阿里云控制台——》产品与服务列表——》弹性计算里的容器镜像服务,进入容器镜像服务控制台
# 点击“个人实例”——》点击左侧“镜像仓库”——》点击“创建镜像仓库”——》输入仓库名称、选择仓库类型、输入仓库的摘要或描述等信息——》点击“下一步”——》选择“本地仓库”——》点击“创建镜像仓库”
#3.设置registry登录密码
# 使用docker login通过密码登录镜像服务实例,需要先设置或获取临时密码或固定密码。
# 容器镜像服务——》个人实例——》仓库管理菜单里的访问凭证——》设置固定密码
# 4.登录阿里云Docker Registry
[root@sunrui ~]# docker logout
Removing login credentials for https://index.docker.io/v1/
[root@sunrui ~]# docker login --username=sunrui12138 registry.cn-hangzhou.aliyuncs.com
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
# 5.构建镜像
[root@sunrui ~]# docker build -t registry.cn-hangzhou.aliyuncs.com/sunrui/docker_test:22.03 .
Sending build context to Docker daemon 865.3kB
Step 1/3 : FROM scratch
--->
Step 2/3 : COPY hello /
---> Using cache
---> 846e09a540e6
Step 3/3 : CMD ["/hello"]
---> Using cache
---> a5dbf1d93254
Successfully built a5dbf1d93254
Successfully tagged registry.cn-hangzhou.aliyuncs.com/sunrui/docker_test:22.03
# 6.将镜像推送到Registry
[root@sunrui ~]# docker push registry.cn-hangzhou.aliyuncs.com/sunrui/docker_test:22.03
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/sunrui/docker_test]
88dc11111fec: Pushed
22.03: digest: sha256:b1d135c19b018cfbbba32085948cb125507b508549a8296568c25a81f5b0709b size: 527
# 7.验证镜像上传
# 访问容器镜像服务控制台——》个人实例——》镜像仓库——》点击仓库名docker_test——》点击镜像版本。可以看到我们上传的镜像。
docker自建注册中心
基于容器安装运行Registry
[root@sunrui ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
3d2430473443: Pull complete
5bf98bf80c2f: Pull complete
950c199aa45b: Pull complete
92504897768b: Pull complete
c6488f74dce8: Pull complete
Digest: sha256:65be6503496c34ec234e89a831ca248b18c2e04c800d9d74af73866e3cda8578
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@sunrui ~]# docker run -d -p 5000:5000 --restart=always --name myregistry -v /opt/data/registry:/var/lib/registry registry
3cac187c798b08d12da5f292a03621e2e27021763481e9313b6f7de57a722354
[root@sunrui ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3cac187c798b registry "/entrypoint.sh /etc…" 29 seconds ago Up 28 seconds 0.0.0.0:5000->5000/tcp myregistry
# 验证刚建立的注册中心
[root@sunrui ~]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":[]} # 此结果说明运行正常,注册中心还没有任何镜像
将镜像上传到自建的注册中心
#1.给已有的镜像打标签符合自建注册中心格式
[root@sunrui ~]# docker tag ubuntu 127.0.0.1:5000/ubuntu:v1
[root@sunrui ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sunrui12138/ubuntu 22.03 93a86f5131ec 3 hours ago 72.8MB
127.0.0.1:5000/ubuntu v1 ba6acccedd29 5 months ago 72.8MB
ubuntu latest ba6acccedd29 5 months ago 72.8MB
[root@sunrui ~]# docker tag sunrui12138/testdocker 127.0.0.1:5000/testdocker:v1
#2.执行镜像上传
[root@sunrui ~]# docker push 127.0.0.1:5000/ubuntu:v1
The push refers to repository [127.0.0.1:5000/ubuntu]
9f54eef41275: Pushed
v1: digest: sha256:7cc0576c7c0ec2384de5cbf245f41567e922aab1b075f3e8ad565f508032df17 size: 529
[root@sunrui ~]# docker push 127.0.0.1:5000/testdocker:v1
The push refers to repository [127.0.0.1:5000/testdocker]
88dc11111fec: Pushed
v1: digest: sha256:b1d135c19b018cfbbba32085948cb125507b508549a8296568c25a81f5b0709b size: 527
#3.执行测试
[root@sunrui ~]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":["testdocker","ubuntu"]}
从自建注册中心下载镜像
[root@sunrui ~]# docker rmi 127.0.0.1:5000/testdocker:v1
Untagged: 127.0.0.1:5000/testdocker:v1
Untagged: 127.0.0.1:5000/testdocker@sha256:b1d135c19b018cfbbba32085948cb125507b508549a8296568c25a81f5b0709b
[root@sunrui ~]# docker pull 127.0.0.1:5000/testdocker:v1
v1: Pulling from testdocker
Digest: sha256:b1d135c19b018cfbbba32085948cb125507b508549a8296568c25a81f5b0709b
Status: Downloaded newer image for 127.0.0.1:5000/testdocker:v1
127.0.0.1:5000/testdocker:v1
[root@sunrui ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:5000/testdocker v1 a5dbf1d93254 3 hours ago 861kB
配置注册中心地址
本地服务器情况下使用127.0.0.1或者localhost作为注册中心地址都是可以的。
但如果使用主机的域名或IP地址提供服务,会报错,这是因为1.3版本后,docker注册中心默认使用的https,但是搭建私有注册中心默认使用的是http。
解决方法:修改docker客户端/etc/docker/daemon.json文件,将地址添加到insecure-registries列表中,允许不安全的通信即可。
# 示例
{
"insecure-registries":["192.168.100.10:5000"]
}
# 保存后重启docker
systemctl restart docker
标签:5000,中心,sunrui,注册,镜像,docker,root,testdocker 来源: https://www.cnblogs.com/kongshuo/p/16077818.html