Undefined Title

Undefined Title

Vagrant-1.6.1 docker provider on MaxOSXを試したときのトラブルシューティング

時間ができたのでVagrant1.6のDocker Provider - SOTAを参考にして、 自分でもちょっと試してみたところ、自分の環境のせいですんなり行かなかったのでメモ。

brew caskでvagrant-1.5.4が入っていて、2014/05/10現在ではまだcaskでは1.6.1になっていない模様。 素直に.dmgをダウンロードする。vagrant_1.6.1.dmg

$ vagrant -v
Vagrant 1.6.1

DockerfileとVagrantfileを用意して、おもむろにvagrant up --provider=docker

$ vagrant up --provider=docker
Bringing machine 'default' up with 'docker' provider...
==> default: Docker host is required. One will be created if necessary...
    default: Vagrant will now create or start a local VM to act as the Docker
    default: host. You'll see the output of the `vagrant up` for this VM below.
    default:  
    default: Box 'mitchellh/boot2docker' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
    default: Loading metadata for box 'mitchellh/boot2docker'
    default: URL: https://vagrantcloud.com/mitchellh/boot2docker
    default: Adding box 'mitchellh/boot2docker' (v0.8.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/mitchellh/boot2docker/version/1/provider/virtualbox.box
    default: Successfully added box 'mitchellh/boot2docker' (v0.8.0) for 'virtualbox'!

ほうほう、新しいboxファイルをダウンロードしてるのね。pathにboot2dockerに入ってるなあ、なんて思いながら見てたらエラー発生。

    default: Importing base box 'mitchellh/boot2docker'...
    default: Matching MAC address for NAT networking...
    default: Checking if box 'mitchellh/boot2docker' is up to date...
    default: Setting the name of the VM: docker-host_default_1399690820764_5342
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 4243 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: 4243, 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.

The forwarded port to 4243 is already in use on the host machine.
あー、なるほど。nativeのboot2dockerのポート4243とかち合ってるわけね。

$ boot2docker stop
[2014-05-10 12:08:06] Shutting down boot2docker-vm...

boot2dockerを止めて、もう一度vagrant up --provider=docker

$ vagrant up --provider=docker
Bringing machine 'default' up with 'docker' provider...
==> default: Docker host is required. One will be created if necessary...
    default: Vagrant will now create or start a local VM to act as the Docker
    default: host. You'll see the output of the `vagrant up` for this VM below.
    default:  
    default: Checking if box 'mitchellh/boot2docker' is up to date...
    default: Fixed port collision for 22 => 2222. Now on port 2200.
    default: Clearing any previously set network interfaces...
----snip----
    default:  Image: a401b6be6f6d
    default: Volume: /var/lib/docker/docker_1399691330_93474:/vagrant
    default:   Port: 8080:80
    default:   Port: 2222:22
    default:  
    default: Container created: 3d94979698e8b9e6
==> default: Starting container...
==> default: Provisioners will not be run since container doesn't support SSH.

今度はちゃんと起動したみたい。 さて、コンテナはどんな状態なのかなあ、とdocker psを叩くと見慣れない表示が、ってまたエラーじゃん。 クライアントコマンドとサーバのバージョンミスマッチってことですかね。

$ docker ps
2014/05/10 12:24:07 Error: client and server don't have same version (client : 1.11, server: 1.10)

dockerコマンド、brewでインストールしてるんだけど、2014/05/10時点で0.11.1がインストールされる。 エラーメッセージの表示はclient : 1.11, server: 1.10ってなってるから、たぶん0.10.xに戻せばいけるんじゃないかと踏んで brewでのdowngradeの方法を探してみる。

brewで特定の古いバージョンのものをインストールする - Qiitaが見つかったので 早速試してみると、無事0.10.0がインストールされたようだ。

$ brew uninstall docker
Uninstalling /usr/local/Cellar/docker/0.11.1...

$ brew versions docker
Warning: brew-versions is unsupported and may be removed soon.
Please use the homebrew-versions tap instead:
  https://github.com/Homebrew/homebrew-versions
0.11.1   git checkout eefa235 Library/Formula/docker.rb
0.11.0   git checkout f4560d2 Library/Formula/docker.rb
0.10.0   git checkout c26c37d Library/Formula/docker.rb
0.9.1    git checkout 6bd6532 Library/Formula/docker.rb
...

$ cd /usr/local
$ git checkout c26c37d /usr/local/Library/Formula/docker.rb
$ brew install docker
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/docker-0.10.0.mavericks.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/docker-0.10.0.mavericks.bottle.tar.gz
...
==> Summary
(beer) /usr/local/Cellar/docker/0.10.0: 9 files, 12M

docker psしてみる。

$ docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                                        NAMES
3d94979698e8        a401b6be6f6d        /usr/sbin/apache2 -D   About an hour ago   Up 7 minutes       0.0.0.0:2222->22/tcp, 0.0.0.0:8080->80/tcp   apache2_default_1399691447   

無事見れたので続きをやろう。