はじめに
Cloud Datalabの「クイックスタート」にはCloud ShellからDatalabを利用する方法が記載されていませんでしたので、「Chromebook での Cloud Datalab の起動」を参考に、Cloud ShellからDatalabを利用する方法をまとめました。
クイックスタート
https://cloud.google.com/datalab/docs/quickstart?hl=ja
Chromebook での Cloud Datalab の起動
https://cloud.google.com/datalab/docs/how-to/datalab-using-shell?hl=ja
手順
1. GCP プロジェクトを選択または作成
https://cloud.google.com/datalab/docs/how-to/datalab-using-shell?hl=ja
に記載の内容と同じです。
2. Google Cloud Platform プロジェクトに対して課金が有効になっていることを確認
https://cloud.google.com/datalab/docs/how-to/datalab-using-shell?hl=ja
に記載の内容と同じです。
3. Google Compute Engine と Cloud Source Repositories API を有効にする
https://cloud.google.com/datalab/docs/how-to/datalab-using-shell?hl=ja
に記載の内容と同じです。
4. Cloud Shell から Cloud Datalab を起動する
Cloud Shellを起動した後、以下のコマンドを実行し、Cloud Datalab VM インスタンスを作成します。
datalab create <instance-name>
以下が表示されたらパスフレーズを入力します。
Enter passphrase for key '/home/user/.ssh/google_compute_engine':
しばらくすると以下のメッセージが表示されます。
表示されたら次の手順に進んでください。
The connection to Datalab is now open and will remain until this command is killed.
Click on the *Web Preview* (square button at top-right), select *Change port > Port 8081*, and start using Datalab.
5. Cloud Datalab ホームページを開く
[ウェブでプレビュー] ボタンを選択したのち、[ポートを変更]を選択します。
ポート番号に8081と入力して、[変更してプレビュー] を選択します。
6. Datalabの画面が開く
Datalabの画面が開きます。
docsの中にサンプルやチュートリアルが入っていました。
切断するにはCloud Shell側で Ctrl + c
を押します。
7. 再接続方法
以下のコマンドで再接続が可能です。
datalab connect --zone <zone> --port 8081 <instance-name>
エラー対応
Quota 'NETWORKS' exceeded
Cloud Datalab VM インスタンスを作成時に以下のエラーが発生した場合は、VPCネットワークの作成可能上限数に達しているものと思われます。
そのため不要なVPCネットワークを削除すれば上記のコマンドが成功します。
Creating the network datalab-network
ERROR: (gcloud.compute.networks.create) Could not fetch resource:
- Quota 'NETWORKS' exceeded. Limit: 5.0 globally.
A nested call to gcloud failed, use --verbosity=debug for more info.