はじめに
vagrantでこれだけは入れとこうと思った設定メモ
入れた設定
vagrantfileにはすでにコメントと設定例が書いてあるのでそれを踏まえて自分がどうしたか?
というのをメモっとく。
- ポートの割り当て
仮想マシンのWebサーバのポート80が、ホストマシンのポート8080に割り当てられるようにする。
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 80, host: 8080
- 仮想ホストのIPアドレスを"192.168.33.10"に設定する
ここで言ってる192.168.33.10は仮想ホスト内のネットワーク上に割り当てられたIPアドレスのことで
sshログインするときのIPアドレスではない(sshログイン時は127.0.0.1になる)
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network "private_network", ip: "192.168.33.10"
- 共有フォルダのパスを指定する
1番目の引数が共有してほしいローカルフォルダのパス(=C:\User\Watya\Vagrant)で、
2番目の引数が共有したときの仮想ホストでのディレクトリパス(/vagrant_data)
ローカルフォルダのカレントディレクトリはVagrantfileがある場所(=C:\User\Watyaになる)
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.synced_folder "./Vagrant", "/vagrant_data"
vagrantfileの変更内容の反映タイミングについて
変更後に
> vagrant up
もしくは
> vagrant reload
で反映される。
設定後の実行ログから共有フォルダの共有っぷりを確認する
==> default: Mounting shared folders...
default: /vagrant => C:/Users/watya
default: /vagrant_data => C:/Users/watya/Vagrant
の記載を見るに
default: /vagrant_data => C:/Users/watya/Vagrant
のやつが自分の設定で書いた箇所になる。
ただ、1行目に
default: /vagrant => C:/Users/watya
とあるので、自分で頑張らなくても今回使用したvagrantの仮想イメージでは
自動で共有フォルダ設定を入れてくれていたようだ。親切だ。。。
↓↓実行時のログを見るといろいろと自分がやった設定が反映されていることが確認できるので記念にメモっとく
C:\Users\watya>vagrant reload
==> default: Checking if box 'nrel/CentOS-6.5-x86_64' version '1.2.0' is up to date...
==> 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: 80 (guest) => 8080 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> 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: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.3.10
default: VirtualBox Version: 6.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => C:/Users/watya
default: /vagrant_data => C:/Users/watya/Vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
C:\Users\watya>
おわりに
元々はこの記事書く気なかったけど
意外と後になるとvagrantfileのパスの記述のあたりが
わからなくなることで苦労したのでメモ残すことにした。