0

我是 vagrant 的新手,在 Windows 7 上使用 1.7.4 和 VirtualBox 5.0.10,并试图弄清楚如何让它以我想要的方式设置和运行 docker 容器,就像这样:

  1. 启动我的 docker 主机,该主机已经配备了最新的 docker 工具,并在cadvisor容器启动时启动 - 我从公开可用的williamyeh/ubuntu-trusty64-docker
  2. 如果(例如)我想使用的 mongo 容器尚未在 docker 主机上创建,只需创建它(不要启动它)
  3. 否则,如果容器已经存在,启动它(不要尝试创建它)

使用我当前的设置,使用 docker 提供程序,在第一次使用vagrant up, usingvagrant halt之后vagrant up会产生这个错误:

Bringing machine 'default' up with 'docker' provider...
==> default: Docker host is required. One will be created if necessary...
    default: Docker host VM is already ready.
==> default: Warning: When using a remote Docker host, forwarded ports will NOT be
==> default: immediately available on your machine. They will still be forwarded on
==> default: the remote machine, however, so if you have a way to access the remote
==> default: machine, then you should be able to access those ports there. This is
==> default: not an error, it is only an informational message.
==> default: Creating the container...
    default:   Name: mongo-container
    default:  Image: mongo
    default:   Port: 27017:27017
A Docker command executed by Vagrant didn't complete successfully!
The command run along with the output from the command is shown
below.

Command: "docker" "run" "--name" "mongo-container" "-d" "-p" "27017:27017" "-d" "mongo"

Stderr: Error response from daemon: Conflict. The name "mongo-container" is already in use by container 7a436a4a3422. You have to remove (or rename) that container to be able to reuse that name.

这是Vagrantfile我用于 docker 主机的:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.hostname = "docker-host"
  config.vm.box_check_update = false
  config.ssh.insert_key = false
  config.vm.box = "williamyeh/ubuntu-trusty64-docker"
  config.vm.network "forwarded_port", guest: 27017, host: 27017
  config.vm.synced_folder ".", "/vagrant", disabled: true
end

...这是码头工人提供者Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider "docker" do |docker|
    docker.vagrant_vagrantfile = "../docker-host/Vagrantfile"
    docker.image = "mongo"
    docker.ports = ['27017:27017']
    docker.name = 'mongo-container'
  end
end
4

1 回答 1

0

好吧,我不确定在我的环境中发生了什么,但是在重新配置我的设置时,我删除并恢复了我的基本 docker 主机映像,从那时起,vagrant up,然后是vagrant halt,然后vagrant updocker提供程序上的工作就像我一样期待它。

无论如何,我想这个问题已经得到了vagrant.

于 2015-12-03T16:57:31.077 回答