与Docker的流动配套 [英] Vagrant provision with Docker
问题描述
我的Vagrantfile是明显的:
VAGRANTFILE_API_VERSION =2
Vagrant.configure VAGRANTFILE_API_VERSION)do | config |
config.vm.box =ubuntu / trusty64
config.vm.synced_folder./project/,/ project /
config.vm.networkforwarding_port,guest :8000,host:8000
config.vm.network:public_network,bridge:'eth0'
config.vm.provisiondockerdo | d |
d.run'ldap',image:'10 .5.6.19:5000 / ldap'
end
end
我的机器上有这个图像:
> sudo docker图片
REPOSITORY TAG IMAGE ID创建的虚拟大小
10.5.6.19:5000/ldap最新ef7f4dcecd65 3个月前930.8 MB
,但是当我尝试使用 vagrant provision
来设置机器时。我实现了一个错误:
从命令中输入stdout:
从命令中输入Stderr:
stdin:不是一个tty
无法找到图像'10 .5.6.19:5000 / ldap:latest'local
time =2014-12-30T13:50:37Z level =fatalmsg =错误:注册表端点无效https://10.14.6.19:5000/v1/:获取https://10.14.6.19:5000/v1/_ping:拨打tcp 10.14.6.19:5000:如果这个私有注册表仅支持HTTP或HTTPS与未知的CA证书,请在守护进程的参数中添加--insecure-registry 10.14.6.19:5000。对于HTTPS,如果您有权限注册表的CA证书,不需要标志;只需将CA证书放在/etc/docker/certs.d/10.14.6.19:5000/ca.crt
我认为这是因为我应该使用某种注册表的图像。有没有办法使用本地图像进行流动资源配置?
您需要在 / etc / default / docker
:
DOCKER_OPTS = - insecure-registry 10.14.6.19: 5000
在旁注中,这在 EXTRA_ARGS
/ var / lib / boot2docker / profile ,以防您使用boot2docker。
有一个很少有选择来解决这个问题:
- 一旦VM启动,手动添加该行。然后重新启动虚拟机。
- 构建一个已经具有上述配置并在Vagrantfile中使用的框
- 使用一个shell配置器设置配置
要使用选项3,请在docker供应商之前加入:
config.vm.provisionshell,
inline:<< -EOS
echo'DOCKER_OPTS = - insecure-registry 10.14.6.19: 5000 $ {DOCKER_OPTS}'\
>> / etc / default / docker
EOS
如果执行 vagrant up
(或 vagrant reload --provision
,以防vm已经在运行),您将能够运行您的图像没有任何问题。
I want to run a docker image on Vagrant machine. My Vagrantfile is straingforward:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.synced_folder "./project/", "/project/"
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.network :public_network, bridge: 'eth0'
config.vm.provision "docker" do |d|
d.run 'ldap', image: '10.5.6.19:5000/ldap'
end
end
I have this image on my machine:
>sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
10.5.6.19:5000/ldap latest ef7f4dcecd65 3 months ago 930.8 MB
but when I try to provision a machine with vagrant provision
. I achieve an error:
Stdout from the command:
Stderr from the command:
stdin: is not a tty
Unable to find image '10.5.6.19:5000/ldap:latest' locally
time="2014-12-30T13:50:37Z" level="fatal" msg="Error: Invalid registry endpoint https://10.14.6.19:5000/v1/: Get https://10.14.6.19:5000/v1/_ping: dial tcp 10.14.6.19:5000: i/o timeout. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 10.14.6.19: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/10.14.6.19:5000/ca.crt"
I think this happens because I should use some kind of registry for images. Is there a way to use local images for vagrant provisioning?
You need to add the following in /etc/default/docker
:
DOCKER_OPTS="--insecure-registry 10.14.6.19:5000"
On a side note, this goes in EXTRA_ARGS
in /var/lib/boot2docker/profile
in case you were using boot2docker.
There are a few options to choose from to fix this:
- Once the VM starts, manually add that line. Then restart the VM.
- Build a box that already has the above config set and use that in your Vagrantfile
- Use a shell provisioner set up that config.
To use option 3, include this before the docker provisioner:
config.vm.provision "shell",
inline: <<-EOS
echo 'DOCKER_OPTS="--insecure-registry 10.14.6.19:5000 ${DOCKER_OPTS}"' \
>> /etc/default/docker
EOS
After this if you execute vagrant up
(or vagrant reload --provision
in case the vm is already running), you'll be able to run your image without any problems.
这篇关于与Docker的流动配套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!