Vagrantの利用は、以下のような魔法のコマンドを叩くところから始まります。
vagrant init hashicorp/precise64
この時、裏側では"Vagrant Cloud"からBoxファイルをダウンロードしています。
"Vagrant Cloud"はBoxファイルをダウンロードするための共有リポジトリとして利用できます。また、今回は試してませんが"Vagrant Share"をするときもVagrant Cloudへのログインアカウントが必要だったりします。
今回は、 技術/運用管理/Vagrant/"Minimal Desktop"インストールのCentOS 6.5のBox作例メモ で作成したCentOSのイメージをVagrant Cloudで公開してみました。
Vagrant Cloudは無料でも使えますが、いくつか制限があります。有料版を使うことで、それらの制限を解除して、企業内のクローズドな開発体制にマッチした機能が利用できます。
Vagrang CloudがWeb上のサービスであるのに対し、"Vagrant Share"はあくまでもクライアント側の機能になります。
今回は試してないので認識が間違ってるかもしれませんが、SSHのトンネリングなどを駆使して、ローカル上で起動しているVagrantのVMに対してインターネットからHTTP(S)でVM上のHTTPサーバにアクセスしたり、LAN内の他のマシンからSSHで接続できるようにするための機能と認識してます。
まずは参考URL:
そんなに複雑な登録作業では無いです。無料利用枠ではVagrant Cloud自体にBoxファイルをアップロードすることは出来ませんので、外部のWebサーバにBoxファイルを配置し、そのURLをVagrant Cloud側に登録する必要があります。
Range機能が使えないWebサーバは対応していない、というような情報も見かけましたので、Vagrantクライアントが直接そのURLからDLするのではなく、Vagrant Cloudが間に入って中継しているのかもしれません。
今回は 技術/運用管理/Vagrant/"Minimal Desktop"インストールのCentOS 6.5のBox作例メモ で作成したboxファイルをAmazon S3にアップして一般公開し、そのURLを登録しました。
ということで今回公開してみたBoxファイルです:
https://vagrantcloud.com/msakamoto-sf/centos65-minimal-desktop
↑のVagrant Cloudのページで、"vagrant init"コマンドの例が表示されてますので、そのままコピペすればOKです。
> vagrant init msakamoto-sf/centos65-minimal-desktop A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
まだこの時点ではBoxファイルのダウンロードは発生しません。"vagrant up"すると、自動的にダウンロードが始まります。
> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'msakamoto-sf/centos65-minimal-desktop' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'msakamoto-sf/centos65-minimal-desktop'
default: URL: https://vagrantcloud.com/msakamoto-sf/centos65-minimal-desktop
==> default: Adding box 'msakamoto-sf/centos65-minimal-desktop' (v0.1.0) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/msakamoto-sf/centos65-minimal-desktop/version/1/provider/virtualbox.b
ox
default: Progress: 100% (Rate: 5066k/s, Estimated time remaining: --:--:--)
==> default: Successfully added box 'msakamoto-sf/centos65-minimal-desktop' (v0.1.0) for 'virtualbox'!
==> default: Importing base box 'msakamoto-sf/centos65-minimal-desktop'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'msakamoto-sf/centos65-minimal-desktop' is up to date...
==> default: Setting the name of the VM: centos65_md_demo
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
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: Warning: Connection timeout. Retrying...
default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => C:/work/tmp/vagrant_ex/t7
以下のディレクトリが作成され、圧縮状態のvmdk, metadata.json, Vagrantfile, box.ovf が展開されます。
$HOME/.vagrant.d/boxes/msakamoto-sf-VAGRANTSLASH-centos65-minimal-desktop/0.1.0/virtualbox
今回は試してませんが、"vagrant init" コマンド、および "vagrant box add" コマンドではURLを指定できますので、LAN内で立ちあげたWebサーバからBoxファイルをDLすることは十分可能と思われます。
※もしかしたら "vagrant init" の場合と "vagrant box add" の場合とでURLを指定した時の動きの中身は違うかも。