容器布置好的情况下:
docker pull registry (一般没啥问题)
修改容器的镜像仓库配置【可配置多个】
vim /etc/docker/daemon.json
一般配置:
{
"insecure-registries":["192.168.0.58:5000"]
}
多个镜像库:
{
"registry-mirrors":["https://fy707np5.mirror.aliyuncs.com"],"insecure-registries":["192.168.0.58:5000"]
}
https://fy707np5.mirror.aliyuncs.com 借用别人的阿里加速镜像库
启动:
docker run -d -p 5000:5000 --name rancher-registry docker.io/registry 【rancher-registry随便定义的rancher库】
修改配置后重启
systemctl daemon-reload
自测
curl http://127.0.0.1:5000/v2/_catalog
[root@mayi-3 ~]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":[]} (空镜像仓库)
功能测试:
拉取:
docker pull hello-world
[root@mayi-3 ~]# docker image ls (查看镜像)
REPOSITORY TAG IMAGE ID CREATED SIZE
rancher/rancher latest ec97968cb7d3 7 days ago 1.12GB
hello-world latest feb5d9fea6a5 4 weeks ago 13.3kB
registry latest b2cb11db9d3d 8 weeks ago 26.2MB
-----------------------------------------------------------------------------------------------------------------------
镜像打标记:(创建镜像不能有大写)
docker tag hello-world:latest 127.0.0.1:5000/hello-world:latest
[root@mayi-3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
rancher/rancher latest ec97968cb7d3 7 days ago 1.12GB
127.0.0.1:5000/hello-world latest feb5d9fea6a5 (ID相同) 4 weeks ago 13.3kB (打标记的镜像)
hello-world latest feb5d9fea6a5 4 weeks ago 13.3kB
registry latest b2cb11db9d3d 8 weeks ago 26.2MB
-----------------------------------------------------------------------------------------------------------------------
推送到私有镜像仓库:
docker push 127.0.0.1:5000/hello-world:latest
[root@mayi-3 ~]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":["hello-world"]}
本地打标记一份镜像
[root@mayi-3 registry_auth]# docker tag registry:latest 127.0.0.1:5000/registry:test
[root@mayi-3 registry_auth]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
rancher/rancher latest ec97968cb7d3 8 days ago 1.12GB
127.0.0.1:5000/hello-world 1.0 feb5d9fea6a5 4 weeks ago 13.3kB
hello-world latest feb5d9fea6a5 4 weeks ago 13.3kB
mayi-3:5000/hello-world 1.0 feb5d9fea6a5 4 weeks ago 13.3kB
127.0.0.1:5000/registry test b2cb11db9d3d 8 weeks ago 26.2MB
regi 2.0 b2cb11db9d3d 8 weeks ago 26.2MB
registry latest b2cb11db9d3d 8 weeks ago 26.2MB
#推送到本地镜像库
[root@mayi-3 registry_auth]# docker push 127.0.0.1:5000/registry:test
The push refers to repository [127.0.0.1:5000/registry]
6da1e15d5d7f: Pushed
d385a2515a0f: Pushed
d661c8a70d1e: Pushed
02ada6f7a843: Pushed
39982b2a789a: Pushed
test: digest: sha256:b0b8dd398630cbb819d9a9c2fbd50561370856874b5d5d935be2e0af07c0ff4c size: 1363
[root@mayi-3 registry_auth]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":["hello-world","registry"]}
#换一台机器拉取(前提配置过 /etc/docker/daemon.json指向)
[root@mayi-2 ~]# docker pull 192.168.0.58:5000/registry:test
test: Pulling from registry
6a428f9f83b0: Pull complete
90cad49de35d: Pull complete
b215d0b40846: Pull complete
429305b6c15c: Pull complete
6f7e10a4e907: Pull complete
Digest: sha256:b0b8dd398630cbb819d9a9c2fbd50561370856874b5d5d935be2e0af07c0ff4c
Status: Downloaded newer image for 192.168.0.58:5000/registry:test
[root@mayi-2 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.0.58:5000/registry test b2cb11db9d3d 8 weeks ago 26.2MB
镜像拉取(本地也有一个镜像仓库)
docker pull 192.168.0.58:5000/registry:test 拉取A仓库到本地
[root@mayi-2 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.0.58:5000/registry test b2cb11db9d3d 8 weeks ago 26.2MB
docker tag 192.168.0.58:5000/registry:test 127.0.0.1:5000/registry:1.1.2 在本地打上一个标记
[root@mayi-2 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:5000/registry 1.1.2 b2cb11db9d3d 8 weeks ago 26.2MB
192.168.0.58:5000/registry test b2cb11db9d3d 8 weeks ago 26.2MB
docker push 127.0.0.1:5000/registry:1.1.2 推送到本地
网友评论