docker 创建本地registry并push镜像

时间:2022-12-26 23:42:43

在本地上创建registry:

# docker run -d -p 5000:5000 -v /opt/ata/registry:/var/lib/registry registry
Unable to find image 'registry:latest' locally
Trying to pull repository docker.io/library/registry ...
latest: Pulling from docker.io/library/registry
79650cf9cc01: Pull complete
70ce42745103: Pull complete
77edd1a7fa4d: Pull complete
432773976ace: Pull complete
3234a47fe5a9: Pull complete
Digest: sha256:a3551c422521617e86927c3ff57e05edf086f1648f4d8524633216ca363d06c2
67d71842f18dd3678232dbd571753543144ac4a10931e658762023e73a270077
[root@localhost Desktop]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test latest 3ab5471af4a3 3 hours ago 117.9 MB
ubuntu latest ebcd9d4fca80 15 hours ago 117.9 MB
docker.io/registry latest 9d0c4eabab4d 5 days ago 33.17 MB

如果在本地上没有registry镜像,将会到docker hub上拉取。这条命令将映射5000端口给registry用,并将仓库镜像存储目录/var/lib/registry/挂到本地/opt/data/registry/下

# netstat -nlpt | grep 5000
tcp6 0 0 :::5000 :::* LISTEN 58433/docker-proxy-

修改镜像标签:

# docker tag test:latest 192.168.163.131:5000/test

push镜像到本地registry:

# docker push 192.168.163.131:5000/test
The push refers to a repository [192.168.163.131:5000/test]
9ec45e5f0334: Pushed
33f1a94ed7fc: Pushed
b27287a6dbce: Pushed
47c2386f248c: Pushed
2be95f0d8a0c: Pushed
2df9b8def18a: Pushed
latest: digest: sha256:d9ab970410b33851a7d9a9b84055348a1d5ec27926f5b5fbd0f214c9f710f10c size: 1564

查看镜像:

[root@localhost repositories]# cd /opt/data/registry/docker/registry/v2/repositories
[root@localhost repositories]# ls
test
[root@localhost repositories]#

也可以通过http的形式来查看registry中的镜像:

[root@localhost repositories]# curl http://192.168.163.131:5000/v2/_catalog
{"repositories":["test"]}