gpt4 book ai didi

docker - 在 Vagrant 下运行 Docker

转载 作者:行者123 更新时间:2023-12-02 18:47:09 25 4
gpt4 key购买 nike

我对运行 Docker 镜像的 Vagrant 1.7.2 有一个令人费解的问题。我正在尝试基于此 Postgres 镜像启动一个普通的 Vanilla 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 进入图像。

最佳答案

正如@Thomasleveil 提到的,has_ssh 指的是容器,而不是 vagrant 在 Windows 和 Mac 机器上启动的主机 VM。

如果你运行 'vagrant global-status' 命令,你会看到实际上创建了两个 vagrant box:

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 写道:

It looks like on first up, Vagrant replaces the insecure SSH key with a generated one. Then on halt / up again, that key is reverted back to the insecure key in the VM, but Vagrant is trying to use the newly generated public key to SSH. Looks like this is because /home/docker/.ssh is part of the root mount on tmpfs.

关于docker - 在 Vagrant 下运行 Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29264772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com