docker 多用户私有仓库

Posted on Posted in docker

docker 多用户私有仓库

玩的很蛋疼, 要骂街了, web 端以后再加

拉取私有镜像仓库

docker pull registry:2

准备工作

# 建立配置文件目录
mkdir conf
# 生成认证文件
openssl req -new -newkey rsa:4096 -days 365 -subj "/CN=localhost" -nodes -x509 -keyout conf/auth.key -out conf/auth.cert
# 添加用户密码, 多用户重复执行, 一行一个
docker run --entrypoint htpasswd registry:2 -Bbn admin admin > conf/htpasswd 

启动

docker run -d --restart=always -e TZ="Asia/Shanghai" \
-v /Users/lhh/vdir:/root/vdir \
-v $(pwd)/conf/auth.cert:/etc/docker/registry/auth.cert \
-v $(pwd)/conf/auth.key:/etc/docker/registry/auth.key \
-v $(pwd)/conf/htpasswd:/etc/docker/registry/htpasswd \
-v $(pwd)/registry:/var/lib/registry \
-e REGISTRY_AUTH_HTPASSWD_REALM=basic \
-e REGISTRY_AUTH=htpasswd \
-e REGISTRY_AUTH_HTPASSWD_PATH=/etc/docker/registry/htpasswd \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/etc/docker/registry/auth.cert \
-e REGISTRY_HTTP_TLS_KEY=/etc/docker/registry/auth.key \
-p 5000:5000 \
--name registry-srv registry:2

登录

docker login https://localhost:5000
Username: admin
Password:
Login Succeeded

登出

docker logout https://localhost:5000
Removing login credentials for localhost:5000

上传镜像

# 打tag, 前面增加私有仓库地址
docker tag 6827bc26a94d localhost:5000/lhh/portainer
docker images
portainer/portainer            latest              6827bc26a94d        7 weeks ago         58.5MB
localhost:5000/lhh/portainer   latest              6827bc26a94d        7 weeks ago         58.5MB

docker push localhost:5000/lhh/portainer
The push refers to repository [localhost:5000/lhh/portainer]
b3a49154f80b: Preparing
dd4969f97241: Preparing
no basic auth credentials  # 需要重新登录, 否则会报这个错

docker login https://localhost:5000
Username: admin
Password:
Login Succeeded

docker push localhost:5000/lhh/portainer
The push refers to repository [localhost:5000/lhh/portainer]
b3a49154f80b: Pushed
dd4969f97241: Pushed
latest: digest: sha256:fc490138952ace0815aa332d5f87ecb392087f5699c825f40fade4a28985165e size: 739

验证

# 浏览器访问这个地址
https://localhost:5000/v2/_catalog?n=100
=> {"repositories":["lhh/bionic","lhh/portainer"]}

删除镜像

看官网的 api ,还要调用 DELETE 方法, 下面方法直接删除

docker exec -it registry-srv /bin/sh # 这里不能是 bash ,特么 registry 里没有 /bin/bash
cat /etc/docker/registry/config.yml # 这里是配置, 找到 /var/lib/registry 存放目录
cd /var/lib/registry/docker/registry/v2/repositories # 这里面即是仓库的存放目录, 找到想删除的, 直接删除即可
» 转载请注明来源:呢喃 » docker 多用户私有仓库

Leave a Reply

Your email address will not be published. Required fields are marked *

17 + eighteen =