Docker部署镜像管理

配置registry

1、创建目录

bash 复制代码
mkdir -p /data/docker/registry

2、创建配置文件

执行命令

bash 复制代码
vi /data/docker/registry/config.yml

文本内容如下

bash 复制代码
version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
  delete:
    enabled: true
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3

3、创建镜像

bash 复制代码
docker run -d --name registry -p 5555:5000 --restart always \
-e TZ=Asia/Shanghai \
-v /data/docker/registry:/var/lib/registry \
-v /data/docker/registry/config.yml:/etc/docker/registry/config.yml \
registry:2

放开策略

bash 复制代码
firewall-cmd --permanent --add-rich-rule "rule family="ipv4" source address="192.168.31.0/24" port port="5555" protocol="tcp" accept" && firewall-cmd --reload

配置registry-ui

registry-ui 是 Docker Registry 的图形化管理界面,它提供了直观的 Web 界面来浏览、搜索和管理私有镜像仓库中的镜像。与命令行工具相比,registry-ui 让镜像管理变得更加简单直观,特别适合团队协作和日常运维。

1、部署

registry-ui 为 registry 的图形化管理界面,注意这个镜像默认没有登录认证功能,因此部署时需要注意安全,建议仅在内部网络或通过 VPN 访问。

部署命令详解

bash 复制代码
docker run -d -p 8809:80 --name registry-ui --restart always \
  -e REGISTRY_URL=http://localhost:8810 \
  -e SINGLE_REGISTRY=true \
  -e DELETE_IMAGES=true \
  -e SHOW_CATALOG_NB_TAGS=true \
  joxit/docker-registry-ui:latest

参数说明:

  • -d:后台运行容器
  • -p 8809:80:将容器的 80 端口映射到宿主机的 8809 端口
  • --name registry-ui:指定容器名称为 registry-ui
  • --restart always:设置容器自动重启策略
  • -e REGISTRY_URL=http://localhost:8810重要 :这里需要根据实际情况修改。如果 registry 容器运行在同一台主机上,且 registry 容器映射的端口是 5555(如前面配置),则应改为 http://localhost:5555http://宿主机IP:5555
  • -e SINGLE_REGISTRY=true:只连接一个 registry
  • -e DELETE_IMAGES=true:启用镜像删除功能
  • -e SHOW_CATALOG_NB_TAGS=true:显示镜像的标签数量

环境变量配置说明

registry-ui 支持多种环境变量配置,常用的还有:

  • REGISTRY_TITLE:设置界面标题,如 -e REGISTRY_TITLE="公司私有镜像仓库"
  • CATALOG_ELEMENTS_LIMIT:限制每页显示的镜像数量,默认 100
  • REGISTRY_SECURED:如果 registry 使用 HTTPS,设置为 true
  • SHOW_CONTENT_DIGEST:显示镜像的摘要信息

2、访问与验证

部署完成后,可以通过以下方式访问:

  1. 浏览器访问 :打开浏览器,输入 http://宿主机IP:8809
  2. 本地访问 :如果在本机部署,访问 http://localhost:8809

首次访问验证:

  • 页面应显示 registry-ui 的欢迎界面
  • 左侧应显示镜像仓库列表(如果配置正确)
  • 点击镜像可以查看标签详情

如果页面显示 "Unable to connect to the registry" 错误,请检查:

  1. REGISTRY_URL 配置是否正确
  2. registry 容器是否正常运行:docker ps | grep registry
  3. 网络连通性:从 registry-ui 容器内能否访问 registry 服务

3、配置反向代理

nginx 复制代码
# Nginx 配置示例
user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8810;
        server_name  localhost;
        server_tokens off;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #location / {  
        #    root   html;
        #    index  index.html index.htm;
        #}

        location / {
            proxy_pass http://localhost:8809/;
            index  index.html index.htm;
            # add_header Access-Control-Allow-Origin *;
            # add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
            # add_header Access-Control-Allow-Headers *;
        }

        # register的对外接口,用于给UI提供接口方法获取tag等
        location /v2 {
            proxy_pass http://localhost:5555;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            # add_header Access-Control-Allow-Origin *;
            # add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
            # add_header Access-Control-Allow-Headers *;
        }

        #error_page  404              /404.html;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

后台接口需要使用Nginx进行代理,统一对外接口为8810

4、创建nginx

bash 复制代码
docker run --name nginx -d --privileged=true --restart=always --network=host \
-e TZ=Asia/Shanghai \
-v /etc/localtime:/etc/localtime:ro \
-v /data/docker/nginx/html:/etc/nginx/html \
-v /data/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
arm64v8/nginx:1.27.3

5、放开策略

bash 复制代码
firewall-cmd --permanent --add-rich-rule "rule family="ipv4" source address="192.168.31.0/24" port port="8810" protocol="tcp" accept" && firewall-cmd --reload

其他

推送镜像到仓库

bash 复制代码
docker tag 046b62ebca48 192.168.31.88:5555/openjdk8:aarch64-ubuntu-jdk8u472-b08
docker push 192.168.31.88:5555/openjdk8:aarch64-ubuntu-jdk8u472-b08

调整Docker配置文件

bash 复制代码
如果报Get https://192.168.31.88:5555/v2/: http: server gave HTTP response to HTTPS client错误,需将"insecure-registries": ["192.168.31.88:5555"]增加到/etc/docker/daemon.json,如
[root@test images]# cat /etc/docker/daemon.json
{
  "iptables": false,
  "data-root": "/data/docker/store",
  "insecure-registries": ["192.168.31.88:5555"],
  "registry-mirrors": ["https://docker.m.daocloud.io",
    "https://huecker.io",
    "https://dockerhub.timeweb.cloud",
    "https://noohub.ru",
    "https://ipv4.mirrors.ustc.edu.cn",
    "https://tivt17e5.mirror.aliyuncs.com"]
}

删除镜像

如果调用接口无法删除镜像

curl -I -XDELETE http://localhost:5555/v2/gateway/manifests/25f3ab7d4da7cd4e954e9b71e40388d334048cdfa2d1dc0e8c61d188f52463bf

进入镜像,配置storage.delete.enabled:true,然后重启镜像即可

bash 复制代码
[root@test ~]# docker exec -it registry /bin/sh
/ # cat /etc/docker/registry/config.yml
version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
  delete:
    enabled: true
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
相关推荐
潘正翔2 小时前
jenkins构建cicd流水线
运维·服务器·ci/cd·容器·自动化·jenkins·cicd
Lost of 程序猿2 小时前
Kubernetes 排障实战:从 CrashLoopBackOff 到网络不通
网络·容器·kubernetes
javachen__2 小时前
Docker一键清理 + 全局限制,告别日志报满
java·docker·容器
可莉丝婷3 小时前
光模块产线自动化设备品牌推荐:艾利特选型指南
运维·自动化
java_logo3 小时前
Docker 部署 FalkorDB:轻松搭建属性图数据库与知识图谱平台
数据库·docker·知识图谱·falkordb·轩辕镜像·falkordb部署教程·falkordb部署文档
型者无疆3 小时前
关于Fcitx5在ubuntu26.04中的位置问题
运维·服务器
mengge.cloud3 小时前
Linux三剑客 grep sed awk 小白基础教程
linux·运维·服务器·网络
Brilliantwxx4 小时前
【Linux】 进程(4)七大进程状态深度解析
linux·运维·算法
HiDev_4 小时前
【非标自动化】2、认识元器件(气源处理组件)
运维·自动化