在使用 docker-machine 提供的主机中允许不安全的注册表

allow insecure registry in host provisioned with docker-machine

有没有为docker的用docker-machine创建的守护进程配置--allow-insecure-ssl

命令:

docker-machine create --driver virtualbox dev 
eval "$(docker-machine env dev)"
docker run myregistry:5000/busybox:latest echo 'hello world'

输出:

Unable to find image 'myregistry:5000/busybox:latest' locally
2015/06/04 16:54:17 Error: v1 ping attempt failed with error: Get          
https://myregistry:5000/v1/_ping: EOF. If this private  
registry supports only HTTP or HTTPS with an unknown CA certificate, 
please add `--insecure-registry myregistry:5000` to the 
daemon's arguments. In the case of HTTPS, if you have access to the 
registry's CA certificate, no need for the flag; simply place the CA 
certificate at /etc/docker/certs.d/myregistry:5000/ca.crt

如果你是运行 docker-machine version v0.2 stable,则无法设置docker选项。但在下一个版本 v0.3 中,此问题已通过创建参数解决。

目前这个功能在RC1上,以后可以使用v0.3.0-RC-1版本或者等待下一个稳定版本v0.3.0(暂定6月16日)发布。

然后使用参数--engine-insecure-registry为docker的守护进程设置--allow-insecure-ssl,例如:

docker-machine create --driver virtualbox --engine-insecure-registry myregistry:5000 dev

之后可以执行:

docker run myregistry:5000/busybox:latest echo 'hello world'

此外,您可以在 project doc 上阅读有关它的信息。

如果你想在你的 docker-机器已经创建后添加另一个注册表,你将必须编辑配置文件: vim~/.docker/machine/machines/dev/config.json

此处解释:https://akrambenaissi.com/2015/11/17/addingediting-insecure-registry-to-docker-machine-afterwards/

编辑 $USER/.docker/machine/machines/default/config.json

    "EngineOptions": {
        "InsecureRegistry": [
            "XXX.XXX.virtual"
        ],
    }

如果您想将不安全的注册表添加到已创建的 docker 机器中,您可以更新 运行 docker VM 中的配置文件。

步骤

  1. 通过 SSH 连接到您的本地 docker 虚拟机。
    注意:如果 'default' 不是您的 docker 机器的名称,则将 'default' 替换为您的 docker 机器名称
    $ docker-machine ssh {machineName}

  2. 打开Docker个人资料
    $ sudo vi /var/lib/boot2docker/profile

  3. 将此行添加到配置文件的底部。如果 EXTRA_ARGS 已经存在,请将不安全的注册表标志添加到 EXTRA_ARGS。替换为您的注册表的路径。

    EXTRA_ARGS=" --insecure-registry myserver.pathTo.registry1:5000 --insecure-registry myserver.pathTo.registry2:5000 --insecure-registry myserver.pathTo.registry3:5000 "

  4. 保存配置文件更改并 'exit' 从 docker-机器 bash 返回到您的机器。然后重新启动 Docker VM 替换为您的 docker-机器名称
    $ docker-machine restart {machineName}

  5. 从您的注册表中拉取或推送某些内容以确保其正常工作

我的设置

docker-机器版本: 0.6.0, build e27fb87
docker-机器驱动程序: virtualbox

环境:

  • docker 守护进程:1.12.3
  • docker 客户端:1.12.2
  • docker api :1.24
  • docker-机器:0.8.2

Before create machine

您可以使用参数设置一个或多个不安全的注册表和注册表镜像。例如:

一个注册表

docker-machine create -d virtualbox --engine-insecure-registry hostname:5000  --engine-registry-mirror http://hostname:5000 n1

多个注册表

docker-machine create -d virtualbox --engine-insecure-registry hostname:5000 --engine-insecure-registry hostname:5001  --engine-registry-mirror http://hostname:5000 n1

After create the machine

您可以编辑 /var/lib/boot2docker/profile 以添加注册表和镜像

docker-machine ssh [machine-name]
vi /var/lib/boot2docker/profile

将注册表和镜像添加到 EXTRA_ARGS

EXTRA_ARGS='
--label provider=virtualbox
--insecure-registry hostname:5000
--insecure-registry hostname:5001
--registry-mirror   http://hostname:5000
--registry-mirror   http://hostname:5001

现在需要重启机器检查一下

docker-machine restart [machine-name] 
docker info 

this method doesn`t work after create the machine

编辑 $USER/.docker/machine/machines/default/config.json

"EngineOptions": {
    "InsecureRegistry": [
        "XXX.XXX.virtual"
    ],
}