仓库搭建
# 下载Registry镜像并启动
$ docker pull registry
Using default tag: latest
latest: Pulling from library/registry
0a6724ff3fcd: Pull complete
d550a247d74f: Pull complete
1a938458ca36: Pull complete
acd758c36fc9: Pull complete
9af6d68b484a: Pull complete
Digest: sha256:d5459fcb27aecc752520df4b492b08358a1912fcdfa454f7d2101d4b09991daa
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
# 运行 Registry
$ docker run -d -v /edc/images/registry:/var/lib/registry -p 5000:5000 --restart=always --name xdp-registry registry
# 查看镜像仓库中的所有镜像 curl http://ip:port/v2/_catalog
$ curl "172.22.19.46:5000/v2/_catalog"
{"repositories":[]}
# 运行 http 访问
$ vim /etc/docker/daemon.json
# 加上下面这一句,这里的"your-server-ip"请换为你的服务器的外网IP地址:
{
"insecure-registries" : [ "172.22.19.46:5000" ]
}
# 重启 docker
$ systemctl restart docker
上传镜像
# 查看镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
leaf latest 2e0e5c2b0d50 2 days ago 682MB
usercenter latest 935002439689 2 days ago 721MB
java 8 d23bdf5b1b1b 4 years ago 643MB
# tag 要上传的镜像打Tag
$ docker tag leaf:test 172.22.19.46:5000/leaf:test
# 再查看镜像,本地多了打上tag的镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
172.22.19.46:5000/leaf test 2e0e5c2b0d50 2 days ago 682MB
leaf latest 2e0e5c2b0d50 2 days ago 682MB
usercenter latest 935002439689 2 days ago 721MB
java 8 d23bdf5b1b1b 4 years ago 643MB
# 上传镜像 leaf:test 到镜像仓库
$ docker push 172.22.19.46:5000/leaf:test
# 查看镜像仓库中的所有镜像,已经上传到镜像仓库了
$ curl "172.22.19.46:5000/v2/_catalog"
{"repositories":["leaf"]}
下载镜像
# 切换到一台没有 leaf:test 的docker服务器
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
leaf latest c2667ad17cb1 2 days ago 682MB
usercenter latest 6b31f9fa9e1d 3 days ago 721MB
java 8 d23bdf5b1b1b 4 years ago 643MB
# 拉取镜像
$ docker pull 172.22.19.46:5000/leaf:test
test: Pulling from leaf
7448db3b31eb: Pull complete
c36604fa7939: Pull complete
29e8ef0e3340: Pull complete
a0c934d2565d: Pull complete
a360a17c9cab: Pull complete
cfcc996af805: Pull complete
2cf014724202: Pull complete
4bc402a00dfe: Pull complete
34bba5de40ce: Pull complete
6896fed66014: Pull complete
Digest: sha256:d012631f35039c381973871b7cd263cfdfd0ff10801f0360b1ce3196f638389c
Status: Downloaded newer image for 172.22.19.46:5000/leaf:test
172.22.19.46:5000/leaf:test
#在查看镜像,下载成功
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
leaf latest c2667ad17cb1 2 days ago 682MB
172.22.19.46:5000/leaf test 2e0e5c2b0d50 2 days ago 682MB
usercenter latest 6b31f9fa9e1d 3 days ago 721MB
java 8 d23bdf5b1b1b 4 years ago 643MB