7.3.4. 不安全的 registry
应避免使用非可信证书的外部 registry(或根本没有证书)。
但是,任何不安全的 registry 都应使用 --insecure-registry
选项来添加,以允许 docker
守护进程从存储库拉取镜像。这与 --add-registry
选项相同,但不会验证 docker
操作。
该 registry 应该使用这两个选项添加来启用搜索的选项;如果有黑名单,则应该执行其他操作,如拉取镜像。
出于测试目的,以下示例显示了如何添加一个 localhost
不安全的 registry。
流程
修改
/etc/containers/registries.conf
配置文件以添加 localhost 不安全的 registry:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意将不安全的 registry 添加到
registry.search
部分以及registry.insecure
部分,以确保它们标记为不安全并列入白名单。添加到registeries.block
部分的任何 registry 都会被阻断,除非也被添加到registry.search
部分。重启
docker
守护进程以使用 registry:sudo systemctl restart docker.service
$ sudo systemctl restart docker.service
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重启
docker
守护进程会导致docker
容器被重启。在
localhost
运行容器镜像 registry pod:sudo docker run -p 5000:5000 registry:2
$ sudo docker run -p 5000:5000 registry:2
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 拉取镜像:
sudo docker pull openshift/hello-openshift
$ sudo docker pull openshift/hello-openshift
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 标记镜像:
sudo docker tag docker.io/openshift/hello-openshift:latest localhost:5000/hello-openshift-local:latest
$ sudo docker tag docker.io/openshift/hello-openshift:latest localhost:5000/hello-openshift-local:latest
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将镜像推送到本地 registry:
sudo docker push localhost:5000/hello-openshift-local:latest
$ sudo docker push localhost:5000/hello-openshift-local:latest
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 使用 Ansible 安装程序,这可以使用
Ansible
主机文件中的openshift_docker_additional_registries
、openshift_docker_blocked_registries
和openshift_docker_insecure_registries
变量进行配置:openshift_docker_additional_registries=registry.redhat.io,my.registry.example.com,localhost:5000 openshift_docker_insecure_registries=localhost:5000 openshift_docker_blocked_registries=all
openshift_docker_additional_registries=registry.redhat.io,my.registry.example.com,localhost:5000 openshift_docker_insecure_registries=localhost:5000 openshift_docker_blocked_registries=all
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意您还可以将
openshift_docker_insecure_registries
变量设置为主机的 IP 地址。0.0.0.0/0
不是一个有效设置。