请注意,您的 Vagrantfile并不是在启动 Vagrant 框/实例时唯一使用的文件。
当你得到这个:
~/dev/vagrant user$ vagrant reload
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 8001 is already in use
on the host machine.
To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 8001, host: 1234
Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.
~/dev/vagrant user$
实际上,您不仅使用 ~/dev/vagrant 中的 Vagrantfile,而且还使用通常位于此处的“box”分发 .box 文件中的文件:
~/.vagrant.d/boxes/trusty/0/virtualbox/Vagrantfile
如果你看一下它,你会发现它有很多默认端口映射:
$ cat ~/.vagrant.d/boxes//trusty/0/virtualbox/Vagrantfile
$script = <<SCRIPT
bzr branch lp:jujuredirector/quickstart /tmp/jujuredir
bash /tmp/jujuredir/setup-juju.sh
SCRIPT
Vagrant.configure("2") do |config|
# This Vagrantfile is auto-generated by 'vagrant package' to contain
# the MAC address of the box. Custom configuration should be placed in
# the actual 'Vagrantfile' in this box.
config.vm.base_mac = "080027DFD2C4"
config.vm.network :forwarded_port, guest: 22, host: 2122, host_ip: "127.0.0.1"
config.vm.network :forwarded_port, guest: 80, host: 6080, host_ip: "127.0.0.1"
config.vm.network :forwarded_port, guest: 8001, host: 8001, host_ip: "127.0.0.1"
config.vm.network "private_network", ip: "172.16.250.15"
config.vm.provision "shell", inline: $script
end
# Load include vagrant file if it exists after the auto-generated
# so it can override any of the settings
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
load include_vagrantfile if File.exist?(include_vagrantfile)
因此,继续编辑此文件以删除有问题的冲突转发端口:
config.vm.network :forwarded_port, guest: 22, host: 2122, host_ip: "127.0.0.1"
config.vm.network :forwarded_port, guest: 80, host: 6080, host_ip: "127.0.0.1"
# config.vm.network :forwarded_port, guest: 8001, host: 8001, host_ip: "127.0.0.1"
经过:
~/dev/vagrant user$ cp ~/.vagrant.d/boxes//trusty/0/virtualbox/Vagrantfile ~/.vagrant.d/boxes//trusty/0/virtualbox/Vagrantfile.old
~/dev/vagrant user$ vi ~/.vagrant.d/boxes//trusty/0/virtualbox/Vagrantfile
并注意其他 Vagrantfiles 包含,即:
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
现在它起作用了:
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'trusty'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant_default_1401234565101_12345
==> 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: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 => 2122 (adapter 1)
default: 80 => 6080 (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: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Home/user/dev/vagrant/vagrant-docker
==> default: Running provisioner: shell...
default: Running: inline script
...
希望这可以帮助。