takaya030の備忘録

PHP、Laravel、Docker などの話がメインです

Windows の docker-machine で Google Cloud Platform に Docker ホストマシンを立てる

Google App Engine で課金設定をした際、2ヶ月有効の 300 USドルのクーポンがついてきたので、試しに GCP に Docker のホストマシンを立ててみました。

検証環境

Docker Toolbox 1.10.3 と同じ構成です。

  • VirtualBox 5.0.16
  • docker 1.10.3
  • docker-machine 0.6.0

Google Cloud SDK のインストール

下記のリンクから Windows 用の Goolge Cloud SDK をインストールします。
Google Cloud SDK - Cloud SDK - Google Cloud Platform

gcloud にログイン

Google Cloud SDK をインストールするとスタートメニューかデスクトップに "Google Cloud SDK Shell" のショートカットが作られるので、それをダブルクリックしてシェルを起動し、以下のコマンドを入力してログインします。

$ gcloud auth login

Docker ホストマシンの作成

$ docker-machine create -d google --google-project <project-id> --google-zone asia-east1-a --google-machine-type "g1-small" gcetest
Running pre-create checks...
(gcetest) Check that the project exists
(gcetest) Check if the instance already exists
Creating machine...
(gcetest) Generating SSH Key
(gcetest) Creating host...
(gcetest) Opening firewall ports
(gcetest) Creating instance
(gcetest) Waiting for Instance
(gcetest) Uploading SSH Key
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\Git\bin\docker-machine.exe env gcetest

インスタンスの確認

$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
dev       -        virtualbox   Stopped                                       Unknown
gcetest   -        google       Running   tcp://104.199.xxx.xxx:2376          v1.10.3

環境変数の設定

msysgit のシェルの場合

$ eval "$(docker-machine env --shell powereshell gcetest)"

ホストマシンへログイン

$ docker-machine ssh gcetest
Welcome to Ubuntu 15.10 (GNU/Linux 4.2.0-18-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud


*** System restart required ***
Last login: Mon Mar 21 12:56:22 2016 from xxx.xxx.xxx.xxx