LoginSignup
110
110

More than 5 years have passed since last update.

boot2dockerからdocker-machineに変えた話

Last updated at Posted at 2015-08-27

ある日、boot2dockerのversionを上げて、boot2docker upをすると以下のwarningを吐いた

WARNING: The 'boot2docker' command line interface is officially deprecated

boot2dockerが非推奨になったみたい。

Please switch to Docker Machineって書いてあるので、docker-machineでローカルのdockerコンテナを管理することにしました。

docker-machineとは?

Machine lets you create Docker hosts on your computer, on cloud providers, and inside your own data center. It automatically creates hosts, installs Docker on them, then configures the docker client to talk to them. A “machine” is the combination of a Docker host and a configured client.

ref: https://docs.docker.com/machine/

virtualBox上とかamazonEC2上とかの環境下でDockerのHostを生成することができるって感じですかね。
複数のHostをこれのdocker-machineで管理できる。

install

$ brew install docker-machine
$ docker-machine --version
docker-machine version 0.4.1 (HEAD)

virtualBox上にdocker-machineの構築

virtualBox上で構築するとする

$ docker-machine create --driver virtualbox dev
Creating VirtualBox VM...
Creating SSH key...
Starting VirtualBox VM...
Starting VM...
To see how to connect Docker to this machine, run: docker-machine env dev
$ docker-machine env dev
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/kohey/.docker/machine/machines/dev"
export DOCKER_MACHINE_NAME="dev"
# Run this command to configure your shell:
# eval "$(docker-machine env dev)"
$ eval "$(docker-machine env dev)"

出来た。

各種コマンド

  • ip確認
$ docker-machine ip dev
  • key周りの確認
$ docker-machine config dev
  • ssh接続
$ docker-machine ssh dev
  • 停止
$ docker-machine stop dev
  • insecure-registryの追加
docker-machine ssh dev "echo $'EXTRA_ARGS=\"--insecure-registry your-registry.jp\"' | sudo tee -a /var/lib/boot2docker/profile && sudo /etc/init.d/docker restart"

コンテナのビルド・push

$ eval "$(docker-machine env dev)"

で環境を反映せずに以下の環境変数がNULLの場合

  • DOCKER_TLS_VERIFY
  • DOCKER_HOST
  • DOCKER_CERT_PATH
  • DOCKER_MACHINE_NAME
$ docker ps

だけだと

Get http:///var/run/docker.sock/v1.20/containers/json: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?

のエラーが出るが、docker-machineのどの環境下を指定してあげると

$ docker $(docker-machine config dev) ps

エラーは出ない。

もちろん毎回毎回$(docker-machine config dev)とか書いてられないと思うので、

$ eval "$(docker-machine env dev)"

してあげると

$ docker ps

がうまくいく。

evalで反映のあとは、各種dockerコマンドが反映されるので問題ない。

あとはboot2dockerで行っていたようにローカルでDockerのコンテナの管理が出来そうである。

感想

AmazonEC2とかDegitalOceanとかにDockerHostを立てて、1つのmachineで管理したい場合とかに便利そう。
boot2dockerがもう非推奨なので、自分の環境下はVirtualBoxをdocker-machineで管理するみたいな体制に変更した。

REF

http://qiita.com/spesnova/items/038af6a8a4e401e3d2aa
http://qiita.com/spesnova/items/073dd64a8a1d580d9ae9
http://dev.classmethod.jp/cloud/aws/ec2-control-using-docker-machine/
http://www.slideshare.net/zembutsu/docker-machine-introduction-cloudmix-11th
http://pocketstudio.jp/log3/2015/07/02/migrate-from-boot2docker-to-docker-machine/

110
110
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
110
110