deprecatesになったBoot2DockerをDocker MachineにMigrationする

たまたまDockerの公式サイトをみたところ以下のような注意書きが。

Note: This release of Docker deprecates the Boot2Docker command line in favor of Docker Machine. Use the Docker Toolbox to install Docker Machine as well as the other Docker tools.

どうやらBoot2Dockerは、deprecatesになったようだ・・。

今はBoot2Dockerに代わってDocker Machineを使用するようなので、公式サイトのBoot2DockerからのMigration方法を参考にMigrationする。

docs.docker.com

Docker Machineをインストールする

Docker Toolboxをダウンロードし、インストールする。インストールを進めていくとDocker Quickstart TerminalまたはKitematicの選択を求められるが、どちらも選択しない。これでdocker-machineコマンドを利用できるようになる。

Boot2DockerからDocker MachineへのMigration

Boot2DockerからのMigration方法に書いてある通り、以下のコマンドを実行する。

$ docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm boot2docker-vm docker-vm

docker-machneのコマンドを叩き、使用できるvmを表示する。

$ docker-machine ls
NAME        ACTIVE   DRIVER       STATE     URL                         SWARM
docker-vm   *        virtualbox   Running   tcp://192.168.1.1:1234

docker-vm環境変数をenvコマンドで取得する。

$ docker-machine env docker-vm
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.1.1:1234"
export DOCKER_CERT_PATH="/Users/horie/.docker/machine/machines/docker-vm"
export DOCKER_MACHINE_NAME="docker-vm"
# Run this command to configure your shell:
# eval "$(docker-machine env docker-vm)"

eval "$(docker-machine env docker-vm)"を実行し、環境変数を定義する。これでdocker clientからdocker-vmを利用してdocker containerを作成できるようになった。毎回↑のコマンドを入力するのは面倒なので、.bashrcや.zshrcなどのshellの設定ファイルにeval "$(docker-machine env docker-vm)"を追加しておく。

hello-world containerを起動する

$ docker run hello-world
Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (Assuming it was not already locally available.)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

For more examples and ideas, visit:
 http://docs.docker.com/userguide/

問題なさそう。

参考