[検証]Docker machineで、DigitalOcean / VirutalBox上にDocker環境構築 


* 試してみた投稿

[Docker MachineでDigital OceanにDocker環境を構築する](http://qiita.com/atsaki/items/472ac40fa53fd98626a0)
[Docker Machine を使って VirtualBox に Dockerホストを立てる](http://qiita.com/spesnova/items/038af6a8a4e401e3d2aa)

* 環境

MacOSX 10.10.4

* Docker machineインストール

2015/7/3現在で
0.3.0が最新でした。

`
$ curl -LO https://github.com/docker/machine/releases/download/v0.3.0/docker-machine_darwin-amd64 mv docker-machine_darwin-amd64 /usr/local/bin/docker-machine
$ chmod +x /usr/local/bin/docker-machine
`

取得したDigital Oceanのアクセストークンを環境変数に入れる
`
$ export DIGITALOCEAN_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxx
`

* DigitalOceanの場合

--digitalocean-region、--digitalocean-sizeのオプションはなくても動きます。

`
$ docker-machine create --driver digitalocean --digitalocean-access-token=$DIGITALOCEAN_ACCESS_TOKEN --digitalocean-image "docker" --digitalocean-region "nyc3" --digitalocean-size "512mb" test
Creating SSH key...
Creating Digital Ocean droplet...
To see how to connect Docker to this machine, run: docker-machine env test
`

Dockerプロセス確認

$ docker-machine ssh test service docker status
docker start/running, process 2076

作成した環境の確認
`
$ docker-machine ls
NAME     ACTIVE   DRIVER         STATE     URL                          SWARM
test            digitalocean   Running   tcp://xxx.xxx.xxx.xxx:2376

いろいろ取得

`
$ docker-machine env test
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://xxx.xxx.xxx.xxx:2376"
export DOCKER_CERT_PATH="/Users/YOUR_HOME/.docker/machine/machines/test"
export DOCKER_MACHINE_NAME="test"
 # Run this command to configure your shell:
 # eval "$(docker-machine env test)"
$ docker-machine config test
--tlsverify --tlscacert="/Users/YOUR_HOME/.docker/machine/machines/test/ca.pem" --tlscert="/Users/YOUR_HOME/.docker/machine/machines/test/cert.pem" --tlskey="/Users/YOUR_HOME/.docker/machine/machines/test/key.pem" -H=tcp://xxx.xxx.xxx.xxx:2376
`

`
$ docker-machine inspect test
{
    "DriverName": "digitalocean",
    "Driver": {
        "AccessToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "DropletID": xxxxxx,
        "DropletName": "",
        "Image": "docker",
        "MachineName": "test",
        "IPAddress": "xxx.xxx.xxx.xxx",
        "Region": "nyc3",
        "SSHKeyID": xxxxxx,
        "SSHUser": "root",
        "SSHPort": 22,
        "Size": "512mb",
        "IPv6": false,
        "Backups": false,
        "PrivateNetworking": false,
        "CaCertPath": "/Users/YOUR_HOME/.docker/machine/certs/ca.pem",
        "PrivateKeyPath": "/Users/YOUR_HOME/.docker/machine/certs/ca-key.pem",
        "DriverKeyPath": "",
        "SwarmMaster": false,
        "SwarmHost": "tcp://0.0.0.0:3376",
        "SwarmDiscovery": ""
    },
    "StorePath": "/Users/YOUR_HOME/.docker/machine/machines/test",
    "HostOptions": {
        "Driver": "",
        "Memory": 0,
        "Disk": 0,
        "EngineOptions": {
            "ArbitraryFlags": [],
            "Dns": null,
            "GraphDir": "",
            "Ipv6": false,
            "InsecureRegistry": [],
            "Labels": [],
            "LogLevel": "",
            "StorageDriver": "",
            "SelinuxEnabled": false,
            "TlsCaCert": "",
            "TlsCert": "",
            "TlsKey": "",
            "TlsVerify": true,
            "RegistryMirror": [],
            "InstallURL": "https://get.docker.com"
        },
        "SwarmOptions": {
            "IsSwarm": false,
            "Address": "",
            "Discovery": "",
            "Master": false,
            "Host": "tcp://0.0.0.0:3376",
            "Image": "swarm:latest",
            "Strategy": "spread",
            "Heartbeat": 0,
            "Overcommit": 0,
            "TlsCaCert": "",
            "TlsCert": "",
            "TlsKey": "",
            "TlsVerify": false,
            "ArbitraryFlags": []
        },
        "AuthOptions": {
            "StorePath": "/Users/YOUR_HOME/.docker/machine/machines/test",
            "CaCertPath": "/Users/YOUR_HOME/.docker/machine/certs/ca.pem",
            "CaCertRemotePath": "",
            "ServerCertPath": "/Users/YOUR_HOME/.docker/machine/certs/server.pem",
            "ServerKeyPath": "/Users/YOUR_HOME/.docker/machine/certs/server-key.pem",
            "ClientKeyPath": "/Users/YOUR_HOME/.docker/machine/certs/key.pem",
            "ServerCertRemotePath": "",
            "ServerKeyRemotePath": "",
            "PrivateKeyPath": "/Users/YOUR_HOME/.docker/machine/certs/ca-key.pem",
            "ClientCertPath": "/Users/YOUR_HOME/.docker/machine/certs/cert.pem"
        }
    },
    "SwarmHost": "",
    "SwarmMaster": false,
    "SwarmDiscovery": "",
    "CaCertPath": "",
    "PrivateKeyPath": "",
    "ServerCertPath": "",
    "ServerKeyPath": "",
    "ClientCertPath": "",
    "ClientKeyPath": ""
}
`


* VirualBox

`
$ 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 ls
NAME   ACTIVE   DRIVER       STATE     URL                         SWARM
dev             virtualbox   Running   tcp://xxx.xxx.xxx.xxx:2376
`

いろいろ取得

`
$ docker-machine env dev
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://xxx.xxx.xxx.xxx:2376"
export DOCKER_CERT_PATH="/Users/YOUR_HOME/.docker/machine/machines/dev"
export DOCKER_MACHINE_NAME="dev"
 # Run this command to configure your shell:
 # eval "$(docker-machine env dev)"
`

ログイン

`
$ docker-machine ssh dev
Boot2Docker version 1.7.0, build master : 7960f90 - Thu Jun 18 18:31:45 UTC 2015
Docker version 1.7.0, build 0baf609
`

デフォルトパスのtcuserでSSHログイン可能

`
$ ssh docker@xxx.xxx.xxx.xxx
docker@xxx.xxx.xxx.xxx's password:
Boot2Docker version 1.7.0, build master : 7960f90 - Thu Jun 18 18:31:45 UTC 2015
Docker version 1.7.0, build 0baf609
docker@dev:~$
`

以上