Vagrant1.5 の新機能である Vagrant Share を試してみる
Vagrant1.5 がリリースされました。
そこで追加された新機能 Vagrant Share
どうやらこれローカルで立ち上げた環境に外部からアクセスできるようになるらしいです。
ってことでどんなものか試してみましょう。
Vagrant Cloudにユーザ登録
ここから Vagrant Cloud のページにアクセスしてユーザ登録しましょう。
Vagrant1.5をインストール
前のバージョンの Vagrant がインストールされているならばまずアンインストールから。
$ sudo rm -rf /Applications/Vagrant $ sudo rm /usr/local/bin/vagrant
削除するだけでOKです。
Virtualbox をインストールしていなければここからインストールして下さい。
次にVagrant1.5をここてください。
環境に合わせて選択、ダブルクリックでインストール完了。
仮想環境の立ち上げ
Vagrant 起動には Vagrantfile が必要です。 下記の例では cetnos6.4 環境に Apache をいれています。
VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "centos64" config.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v0.1.0/centos64-x86_64-20131030.box" config.vm.network :private_network, ip: "192.168.33.60" config.vm.provision "shell", inline: <<-EOT yum update yum install -y httpd rm -rf /var/www ln -fs /vagrant /var/www echo "Hello yudusuk!" > /vagrant/index.html EOT end
では仮想マシンを起動してみましょう
$ vagrant up
vagrant login
ではログインしてみましょう。
$ vagrant login In a moment we'll ask for your username and password to Vagrant Cloud. After authenticating, we will store an access token locally. Your login details will be transmitted over a secure connection, and are never stored on disk locally. If you don't have a Vagrant Cloud account, sign up at vagrantcloud.com Username or Email: "Vagrant Cloudで登録したメールアドレス" Password (will be hidden): "Vagrant Cloudで登録したパスワード" You're now logged in!
You’re now logged in!が表示されればログイン完了
vagrant share
では準備が整ったのでいよいよVagrant Shareコマンドを叩いてみましょう。
$ vagrant share ==> default: Detecting network information for machine... default: Local HTTP port: 80 default: Local HTTPS port: disabled ==> default: Checking authentication and authorization... ==> default: Creating Vagrant Share session... default: Share will be at: lively-mule-8234 ==> default: Your Vagrant Share is running! Name: lively-mule-8234 ==> default: URL: http://lively-mule-8234.vagrantshare.com
一番下にあるURLでアクセスできるようになります。
* http://lively-mule-8234.vagrantshare.com
すごい!!
ちなみにURLは毎回かわるようです。
終了したいときは
Ctrl + C
再び上記のURLにアクセスしてもなにもでなくなります。
まとめ
同じネットワーク同士の人ならpublic_network設定でもいいですが、 リモート環境の人に動作を見せたい時に重宝しますね。