Vagrantをチームで利用するときに、配布したVagrantfileを使うメンバーが時折おきるトラブルをまとめました.
チーム運用の際にメンバーに共有するつもりで作ったので参考にしてくだい.
基本
まずは基本コマンドから説明します.
Vagrantfile
ファイルが置かれているディレクトリか、その下層のディレクトリで
vagrant
コマンドが利用できます.
コマンド中の[name]
は複数のVMがある時に指定するものです.
コマンド | 説明 |
---|---|
vagrant status [name] |
ステータス表示 |
vagrant suspend [name] |
サスペンド |
vagrant up [name] |
起動 (サスペンドからの復帰等) |
vagrant halt [name] |
シャットダウン |
vagrant reload [name] |
再起動 |
vagrant destroy [name] |
イメージの削除 |
vagrant ssh [name] |
SSH接続 |
SSHの設定
sshのconfigを設定しておくと、幸せになれます.
vagrant ssh-config
コマンドでconfigの雛形が出力してくれます.
この結果を~/.ssh/config
等に書いてssh ${HOST}
で接続できるようになります.
以下の出力結果の場合はssh default
で繋がります.
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/foo/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes
トラブルシューティング
ホスト/ゲスト間で/vagrant
以下のパーミッションが異なる
Windows環境の場合、ゲストOSがLinux環境だと共有フォルダでマウントしたディレクトリ以下が777
のパーミッションになります.
根本解決にはなりませんがVagrantfile
でマウントしたときのファイルとディレクトリのパーミッションが指定できます.
config.vm.synced_folder “./”, “/vagrant”, owner: ‘root’, group: ‘root’, mount_options: ['dmode=777', 'fmode=666']
/vagrant
がマウントされない
ゲストOS上で/vagrant
がマウントされない場合があります、
VirtualBox等のバージョンアップ等でマウントされなくなる様です.
この場合以下のコマンドをゲストOS上で実行することでマウントできるようになります.
sudo /etc/init.d/vboxadd setup
その後、念のためゲストOSを再起動するとマウントされると思います.
以下のコマンドをホスト側で実行すると再起動します.
vagrant reload
ちなみにマウントできない時のエラーは以下のような感じ
Failed to mount folders in Linux guest. This is usually beacuse
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
The error output from the last command was:
/sbin/mount.vboxsf: mounting failed with the error: No such device
ネットワークが使えなくなった
ゲストOSからグローバルへpingが通っていたものが、使えなくなることがあるようです.
vagrant reload
等で再起動すれば直ったらしいですが、掴めていません.
windowsのノートPCでサスペンドからの復帰時に起きた事象です.