7.3.2. Docker 外部 registry 白名单和黑名单


通过为 docker 守护进程配置 registriesblock_registries 标志,可以将 Docker 配置为阻止来自外部 registry 的操作。

流程
  1. 使用 registries 标记将允许的 registry 添加到 /etc/containers/registries.conf 文件中:

    registries:
      - registry.redhat.io
      - my.registry.example.com
    注意

    docker.io registry 可使用相同的方法添加。

  2. 阻止其余的 registry:

    block_registries:
       - all
  3. 阻止旧版本中的 registry 的其余部分:

    BLOCK_REGISTRY='--block-registry=all'
  4. 重启 docker 守护进程:

    $ sudo systemctl restart docker.service

    重启 docker 守护进程会导致 docker 容器重启。

  5. 在本例中,docker.io registry 已被列入黑名单,因此有关该 registry 的任何操作都会失败:

    $ sudo docker pull hello-world
    Using default tag: latest
    Trying to pull repository registry.redhat.io/hello-world ...
    Trying to pull repository my.registry.example.com/hello-world ...
    Trying to pull repository registry.redhat.io/hello-world ...
    unknown: Not Found
    $ sudo docker pull docker.io/hello-world
    Using default tag: latest
    Trying to pull repository docker.io/library/hello-world ...
    All endpoints blocked.

    通过再次修改文件并重新启动服务,将 docker.io 添加会 registry 变量。

    registries:
      - registry.redhat.io
      - my.registry.example.com
      - docker.io
    block_registries:
      - all

    或者

    ADD_REGISTRY="--add-registry=registry.redhat.io --add-registry=my.registry.example.com --add-registry=docker.io"
    BLOCK_REGISTRY='--block-registry=all'
  6. 重启 Docker 服务:

    $ sudo systemctl restart docker
  7. 验证镜像现在可拉取(pull):

    $ sudo docker pull docker.io/hello-world
    Using default tag: latest
    Trying to pull repository docker.io/library/hello-world ...
    latest: Pulling from docker.io/library/hello-world
    
    9a0669468bf7: Pull complete
    Digest: sha256:0e06ef5e1945a718b02a8c319e15bae44f47039005530bc617a5d071190ed3fc
  8. 如果需要使用外部 registry,例如修改所有需要使用该 registry 的节点主机中的 docker 守护进程配置文件,请在这些节点上创建一个黑名单以避免恶意容器被执行。

    使用 Ansible 安装程序,这可以使用 Ansible 主机文件中的 openshift_docker_additional_registriesopenshift_docker_blocked_registries 变量进行配置:

    openshift_docker_additional_registries=registry.redhat.io,my.registry.example.com
    openshift_docker_blocked_registries=all
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部