我在使用Vagrant 1.7.2运行Docker镜像时遇到了一个令人费解的问题。我试图基于这个Postgres图像启动普通的香草Docker容器。如果我理解正确,Docker应不尝试ssh到此图像,而只是将其旋转并暴露端口5432.
我的Vagrant文件如下:
Vagrant.configure("2") do |config|
config.vm.network :forwarded_port, guest: 5432, host: 5432
config.vm.provider "docker" do |d|
d.image = "tutum/jboss"
d.ports = ["5432:5432"]
d.env = {
POSTGRES_PASSWORD: 'postgres'
}
d.has_ssh = false
end
end
vagrant up --provider=docker
的输出是:
vagrant up --provider=docker
Bringing machine 'default' up with 'docker' provider...
==> default: Docker host is required. One will be created if necessary...
default: Vagrant will now create or start a local VM to act as the Docker
default: host. You'll see the output of the `vagrant up` for this VM below.
default:
default: Checking if box 'mitchellh/boot2docker' is up to date...
default: Clearing any previously set forwarded ports...
default: Clearing any previously set network interfaces...
default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Forwarding ports...
default: 2375 => 2375 (adapter 1)
default: 22 => 2222 (adapter 1)
default: Running 'pre-boot' VM customizations...
default: Booting VM...
default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: docker
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
此时,该过程只是试图ssh到图像中。
答案 0 :(得分:4)
正如@Thomasleveil所提到的,has_ssh指的是容器,而不是流浪汉在Windows和Mac计算机上启动的主机虚拟机。
如果你运行'vagrant global-status'命令,你会发现实际上有两个流浪盒被创建:
id name provider state directory
--------------------------------------------------------------------
1172194 default virtualbox running {dir}/.vagrant.d/data/docker-host
d19539e default docker preparing {your image}
你必须通过调用'vagrant destroy {docker-host id}'来破坏docker-host镜像,然后将以下行添加到你的Vagrantfile中:
config.ssh.insert_key = false
再一次打电话''vagrant up --provider = docker',你应该没问题。
至于为什么你甚至需要首先添加这一行,this github issue解释得很清楚。
AndyShinn写道:
看起来首先,Vagrant用生成的SSH密钥替换不安全的SSH密钥。然后再次暂停/重新启动,该密钥将恢复为VM中的不安全密钥,但Vagrant正在尝试使用新生成的公钥来SSH。看起来这是因为/home/docker/.ssh是tmpfs上root权限的一部分。
答案 1 :(得分:1)
这样的Vagrantfile会让Vagrant创建一个VM(运行ssh)来充当Docker主机。一旦创建,引导和配置该VM(通过ssh),Vagrant将告诉Docker主机提取tutum/jboss
docker镜像并运行一个容器(没有ssh)。
您的问题是Vagrant无法通过ssh连接到应该充当Docker主机的VM mitchellh/boot2docker
。