Docker 创建本地镜像仓库


docker 安装:https://www.cnblogs.com/jhxxb/p/11410816.html

 

安装仓库服务

配置 https 权限支持

修改 docker 配置文件:/etc/docker/daemon.json,增加内容 "insecure-registries": ["10.74.2.71:5000"]

{
  "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com", "https://hub-mirror.c.163.com"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "insecure-registries": ["10.74.2.71:5000"]
}

重启服务

systemctl daemon-reload && systemctl restart docker

 

在本地创建一个镜像仓库服务

docker run -d --name registry \
--restart=always \
-v /mnt/registry:/var/lib/registry \
-p 5000:5000 \
registry

--restart always:随 docker 开机自启动

-v /mnt/registry:/var/lib/registry:自定义镜像存放路径

--privileged=true:让 container 内的 root 拥有真正的 root 权限

-e REGISTRY_STORAGE_DELETE_ENABLED=true:开启删除镜像的功能

编辑配置

https://github.com/distribution/distribution/blob/main/docs/configuration.md

docker exec -it registry vi etc/docker/registry/config.yml


version: 0.1
log:
  fields:
    service: registry
storage:
  delete:
    enabled: true
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
    Access-Control-Allow-Origin: ['*']
    Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']
    Access-Control-Expose-Headers: ['Docker-Content-Digest']
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3


docker restart registry

删除不会实际删除镜像文件,需要手动清理

https://docs.docker.com/registry/garbage-collection/

docker exec -it registry sh
registry garbage-collect /etc/docker/registry/config.yml
du -sch /var/lib/registry

 

基本使用

拷贝一个镜像,并重命名(用于测试下一步的上传)

docker tag 28dzdaf856cb 11.71.91.51:5000/openjdk:alpine

 

推送镜像到本地镜像仓库

docker push 11.71.91.51:5000/openjdk:alpine

 

拉取本地仓库中的镜像

docker pull 11.71.91.51:5000/openjdk:alpine

 

查看(API)

https://github.com/distribution/distribution/blob/main/docs/spec/api.md

查看本地镜像仓库的镜像

curl http://11.71.91.51:5000/v2/_catalog

查看本地镜像仓库镜像的 tag

curl http://11.71.91.51:5000/v2/openjdk/tags/list

 

三方 UI 界面

https://hub.docker.com/r/joxit/docker-registry-ui

https://github.com/Joxit/docker-registry-ui

docker run -d --name registry-ui \
--restart=always \
-e REGISTRY_URL=http://10.74.2.71:5000 \
-e DELETE_IMAGES=true \
-p 5001:80 \
joxit/docker-registry-ui

访问服务器 5001 端口

 


https://hub.docker.com/_/registry

https://docs.docker.com/registry/

https://www.cnblogs.com/wswind/p/11854854.html

https://blog.csdn.net/xts_huangxin/article/details/51693890


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM