vagrantを起動しようとしたらportがかぶっているとエラーがでる


vagrantで複数のVMを立ち上げているときにエラーがでました(☝ ՞ਊ ՞)

vagrant upでエラーが発生

VMのAが立ち上がっている状態で、VMのBをvagrant upしました。

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 2222 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: 22, 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.

ぎゃーエラーが出ましたなんじゃこれ:(;゙゚’ω゚’):

すでに立ち上がっているVMを止める

似たような事例があるので呼んでみるといま立ち上がっているVMをsuspendしろとあります。

VMのAのほうをhalします。

vagrant halt
[default] Attempting graceful shutdown of VM…

VMのAが停止しました。

次にVMのBを立ち上げます。

vagrant up
Bringing machine ‘default’ up with ‘virtualbox’ provider…
[default] Resuming suspended VM…
[default] Booting VM…
[default] Waiting for machine to boot. This may take a few minutes…
[default] Machine booted and ready!

今度はvagrant upが成功しました。

動作確認

ボクの要望としてはVMのAとBの両方が立ち上がって欲しかいので、Aのほうも立ち上げます。

vagrant up
Bringing machine ‘default’ up with ‘virtualbox’ provider…
[default] Clearing any previously set forwarded ports…
[Berkshelf] Skipping Berkshelf with –no-provision
[default] Fixed port collision for 22 => 2222. Now on port 2200.
[default] Clearing any previously set network interfaces…
[default] Preparing network interfaces based on configuration…
[default] Forwarding ports…
[default] — 22 => 2200 (adapter 1)
[default] — 80 => 8080 (adapter 1)
[default] Running ‘pre-boot’ VM customizations…
[default] Booting VM…
[default] Waiting for machine to boot. This may take a few minutes…
[default] Machine booted and ready!
[default] The guest additions on this VM do not match the installed version of
VirtualBox! In most cases this is fine, but in rare cases it can
prevent things such as shared folders from working properly. If you see
shared folder errors, please make sure the guest additions within the
virtual machine match the version of VirtualBox you have installed on
your host and reload your VM.

Guest Additions Version: 4.2.12
VirtualBox Version: 4.3
[default] Configuring and enabling network interfaces…
[default] Exporting NFS shared folders…
Preparing to edit /etc/exports. Administrator privileges will be required…
[default] Mounting NFS shared folders…
[default] Mounting shared folders…
[default] — /vagrant
[default] VM already provisioned. Run `vagrant provision` or use `–provision` to force it

おお!問題なく立ち上がりました。やったね(☝ ՞ਊ ՞)


コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です