Vagrant docker provider:创建并启动vs run

时间:2015-12-03 15:52:55

标签: docker vagrant vagrantfile vagrant-windows

我是流浪汉的新手,在Windows 7上使用1.7.4与VirtualBox 5.0.10并试图弄清楚如何设置和运行我喜欢的Docker容器,这是像这样:

  1. 启动我的docker主机,该主机已经配置了最新的docker工具和已启动cadvisor容器的靴子 - 我从公开的williamyeh/ubuntu-trusty64-docker
  2. 获取此框
  3. 如果(例如)我还没有在docker主机上创建我想使用的mongo容器,只需创建它(不要启动它)
  4. 否则,如果容器已经存在,请启动它(不要尝试创建它)
  5. 使用Docker提供程序进行当前设置,首次使用vagrant up后,使用vagrant 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我用于泊坞主机:

    # -*- 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
    

    ...这里是docker provider 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
    

1 个答案:

答案 0 :(得分:0)

好吧,我不确定在我的环境中发生了什么,但在重新配置我的设置时,我删除并恢复了我的基本泊坞主机图像,从那时起,vagrant up,然后vagrant halt后面vagrant up docker vagrant提供的工作与我期望的完全一样。

无论如何,我想AddFolderCommand已经支持这个问题了。