0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

docker-machineのシングルコマンドで、docker-host作成する

Last updated at Posted at 2015-03-16

docker-machine を使うと docker daemonを local-machineかcloud-providerに簡単インストールできます。

環境 *NIX

  • docker

まずdocker-machine binaryファイルをダウンロードします。
https://docs.docker.com/machine/

バージョン確認(OS X)

$docker-machine -v
docker-machine_darwin version 0.1.0

ローカルにインストール(virtualboxが必須です)

$ docker-machine create --driver virtualbox dev
INFO[0000] Creating SSH key...
INFO[0000] Creating VirtualBox VM...
INFO[0007] Starting VirtualBox VM...
INFO[0007] Waiting for VM to start...
INFO[0038] "dev" has been created and is now the active machine
INFO[0038] To connect: docker $(docker-machine config dev) ps

google-cloudにインストールします

$ docker-machine create -d google --google-zone asia-east1-b --google-project awesome-project dev-gcp

docker-host一覧

$ docker-machine ls
NAME      ACTIVE   DRIVER         STATE     URL
dev       *        virtualbox     Running   tcp://192.168.99.103:2376
dev-gcp            google         Running   tcp://104.155.212.199:2376
staging            digitalocean   Running   tcp://100.236.50.118:2376

dev-gcpに mongodb containerをインストール(30秒以内!)

$ docker `docker-machine config dev-gcp` run --name mongodb-3.0 -d mongo:latest
cc7aded0fb5439c6e54edd6234e06dd61c374248a9a42191f256d461d3c5xxxx
$ docker `docker-machine config dev` ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
cc7aded0fb54        mongo:latest        "/entrypoint.sh mong   4 seconds ago       Up 3 seconds        27017/tcp           mongodb-3.0

mongodb-containerをcliにします

$ docker `docker-machine config dev-gcp` run --rm -t -i --name mongodb-3.0-cli mongo:latest /bin/bash
root@90c92aeb9f8f:/# mongo 172.17.0.5 // mongodb-containerの IPaddress
MongoDB shell version: 3.0.0
connecting to: 172.17.0.5/test
Welcome to the MongoDB shell.
For interactive help, type "help".

作成したmachine(docker-host)に ssh接続します

$ docker-machine ssh dev-gcp

machineをremoveします。

$ docker-machine rm dev-gcp
INFO[0000] Deleting instance.
INFO[0001] Waiting for instance to delete.
INFO[0026] Deleting disk.
INFO[0027] Waiting for disk to delete.

docker machineはまだ productionではあるません。
でも、できることがたくさんあると思います。cloudinitの開発も進めています。
うちはもうproductionで使ってます。インスタンス作成めっちゃ便利です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?