Docker Machineを使うとローカルのDocker環境構築するのも簡単だったし、クラウドにデプロイするのも超簡単だった。
インストールはドキュメントの通り。 Macの場合は
($ brew install docker)
$ brew install docker-machine
で。docker-machineでセットアップすると、あたかもdockerホストで作業しているかのようにローカルPC上でdocker
コマンドを使える。ホストがBoot2DockerでもAmazon EC2でもGoogle Compute Engineでも透過的に扱える!
一番安価なDigitalOceanの例をメモする。
DigitalOcean側のセットアップはこの記事の通り。
イメージ (Dockerホスト)作成。リージョンは一番近いシンガポール(sgp1
)にしてみた。do1
はイメージ名。
$ docker-machine create -d digitalocean --digitalocean-region sgp1 --digitalocean-access-token (アクセストークン) do1
INFO[0001] Creating SSH key...
INFO[0002] Creating Digital Ocean droplet...
INFO[0146] "do1" has been created and is now the active machine.
INFO[0146] To point your Docker client at it, run this in your shell: eval "$(docker-machine env do1)"
メモリサイズはデフォルトで512mbである。変えたいときは--digitalocean-size 1gb
のように指定する。
docker-machine ls
でdo1
が起動しているのを確認できる。
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
dev virtualbox Running tcp://192.168.99.100:2376
do1 * digitalocean Running tcp://128.199.143.37:2376
Dropletsページをみてもイメージができているのがわかる。
docker-machine env do1
をeval
すると、docker
コマンドがDigitalOcean(do1
)を向くようになる。
$ eval "$(docker-machine env do1)"
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
早速、簡単なDockerイメージを実行してみる。
$ docker run -p 80:80 nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from nginx
3cb35ae859e7: Pull complete
41b730702607: Pull complete
97d05af69c46: Pull complete
55516e2f2530: Pull complete
7ed37354d38d: Pull complete
e7e840eed70b: Pull complete
0b5e8be9b692: Pull complete
439e7909f795: Pull complete
ee8776c93fde: Pull complete
50c46b6286b9: Pull complete
e59ba510498b: Pull complete
42a3cf88f3f0: Already exists
nginx:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:a0270163dd1bbb456d77996eb77114b0abd6f82208bd3a30527a8bf523879b8b
Status: Downloaded newer image for nginx:latest
IPはdocker-machine ip do1
でわかるから、
$ open http://`docker-machine ip do1`
で、Nginxのホームページが表示される。
docker-machine ssh do1
でDockerホストにログインもできる。
$ docker-machine ssh do1
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-43-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Sun May 3 16:00:07 EDT 2015
System load: 0.97 Processes: 70
Usage of /: 11.5% of 19.56GB Users logged in: 0
Memory usage: 12% IP address for eth0: 128.199.143.37
Swap usage: 0% IP address for docker0: 172.17.42.1
Graph this data and manage this system at:
https://landscape.canonical.com/
オプションの詳細はこちら。
Docker Machine良いね。
このページがめちゃくちゃ助かる。
このリンクからDigitalOceanのアカウントを作ってくれると、$10クーポンがつく。(そして私には$25クーポンがつく...w)