docker私有仓库操作(搭建、运行、添加、删除)

参考:https://yeasy.gitbooks.io/docker_practice/content/repository/registry.html

运行私有仓库

直接用docker的方式运行registry镜像省了搭建步骤

$ docker run -d \
    -p 5000:5000 \
    -v /opt/data/registry:/var/lib/registry \
    registry

TIPS:

数据目录和库文件目录可以自己设置,甚至可以给私有仓库取名字,如下:

$ docker run -d -p 5000:5000 --privileged=true -v /home/.registry/data:/home/.registry/lib  --restart=always --name pirvi_registry registry

指定了名字之后,如果想重启,可以使用命令:

$ docker restart pirvi_registry

如果是执行run的话相当于启动了一个新的容器,容器ID就会变,如果还是使用刚才的参数并且--name相同,那么会报如下错误:

docker: Error response from daemon: Conflict. The container name "/pirvi_registry" is already in use by container "194a22f33b1af366f036cc7691a1d1d918e55150bbc170e8e8fd171e52f0f273". You have to remove (or rename) that container to be able to reuse that name.

因此如果要重新启动容器请使用docker restart [name]命令。


上传

把镜像放入私有仓库

$ docker image ls
REPOSITORY                        TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu                            latest              ba5877dc9bec        6 weeks ago         192.7 MB
$ docker tag ubuntu:latest 127.0.0.1:5000/ubuntu:latest
$ docker image ls
REPOSITORY                        TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu                            latest              ba5877dc9bec        6 weeks ago         192.7 MB
127.0.0.1:5000/ubuntu:latest      latest              ba5877dc9bec        6 weeks ago         192.7 MB

验证

$ docker image rm 127.0.0.1:5000/ubuntu:latest

$ docker pull 127.0.0.1:5000/ubuntu:latest
Pulling repository 127.0.0.1:5000/ubuntu:latest
ba5877dc9bec: Download complete
511136ea3c5a: Download complete
9bad880da3d2: Download complete
25f11f5fb0cb: Download complete
ebc34468f71d: Download complete
2318d26665ef: Download complete

$ docker image ls
REPOSITORY                         TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
127.0.0.1:5000/ubuntu:latest       latest              ba5877dc9bec        6 weeks ago         192.7 MB

查看

查看私有仓库中的镜像

$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":["ubuntu","nginx"]}

查看具体的某个镜像的版本

[root@kub2 ~]# curl 127.0.0.1:5000/v2/nginx/tags/list
{"name":"nginx","tags":["1.7.9"]}

有人写了现成的脚本:查看仓库镜像脚本

删除私有仓库的镜像

$ curl -I -X DELETE http://127.0.0.1:5000/v2/fbgweb/manifests/sha256:6a67ba482a8dd4f8143ac96b1dcffa5e45af95b8d3e37aeba72401a5afd7ab8e

其中要删除的镜像的sha256可以通过docker pull该镜像之后的打印中看出来:

$ docker push 127.0.0.1:5000/radial/busyboxplus:curl
The push refers to repository [127.0.0.1:5000/radial/busyboxplus]
5f70bf18a086: Mounted from nginx 
430380561a4f: Pushed 
165264a81ac2: Pushed 
curl: digest: sha256:ef538eae80f40015736f1ee308d74b4f38f74e978c65522ce64abdf8c8c5e0d6 size: 1765

垃圾回收

查看私有仓库的容器

$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                    NAMES
194a22f33b1a        registry               "/entrypoint.sh /etc…"   4 days ago          Up 4 days           0.0.0.0:5000->5000/tcp   pirvi_registry                                 

用tty登录到容器

$ docker exec -it 194a22f33b1a /bin/sh

执行垃圾回收命令

~ # registry garbage-collect /etc/docker/registry/config.yml 
31 blobs marked, 5 blobs eligible for deletion
blob eligible for deletion: sha256:5e7cf06c8745d0985f94191c60aad8b87371c8a674162525bff0efccdb805931
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/5e/5e7cf06c8745d0985f94191c60aad8b87371c8a674162525bff0efccdb805931  go.version=go1.7.6 instance.id=c38f4c35-9914-4b77-a59f-ea584137fae0
...

猜你喜欢

转载自www.cnblogs.com/bugutian/p/11387840.html