我是流浪汉的新手,在Windows 7上使用1.7.4和VirtualBox 5.0.10,并试图弄清楚如何按照我想要的方式设置和运行docker容器,如下所示:
- 启动我的docker主机,它已经配备了最新的docker工具,并在启动
cadvisor
容器的情况下启动-我从公开可用的williamyeh/ubuntu-trusty64-docker
获得此框 - 如果(例如)我想使用的mongo容器还没有在docker主机上创建,只需创建它(不要启动它)
- 否则,如果容器已经存在,请启动它(不要尝试创建它)
在我目前的设置中,使用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.
这是我用于docker主机的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提供商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
嗯,我不确定我的环境中发生了什么,但在重新配置设置时,我删除并恢复了我的基本docker主机映像,从那时起,docker
提供程序上的vagrant up
、vagrant halt
和vagrant up
的工作方式与我预期的完全一样。
无论如何,我想这个问题已经得到了vagrant
的支持。