よく使うgcloudコマンドたち


一般

自分のプロジェクト一覧を表示

gcloud projects list

cloud sdkのプロパティを見る

gcloud config list

プロジェクト切り替え

gcloud config set project <your-project-id>

GCE

インスタンス一覧を見る

gcloud compute instances list

インスタンスの作成(centos-7で)

gcloud compute instances create <your-instance-name> --project <your-project-name> --image-family centos-7

使用可能なimage一覧を見る

gcloud compute images list

インスタンスの起動・停止

gcloud compute instances start <your-instance-name>
gcloud compute instances stop <your-instance-name>

インスタンスにssh

gcloud compute ssh <your-instance-name>

通常のsshコマンドで接続できるように設定

gcloud compute config-ssh
~/.ssh/configに稼働中のインスタンスへの接続設定が作られる。
ssh <your-instance-name>.<zone>.<your-project-id>
ssh [tab]で

インスタンスへローカルのファイルをコピーする

gcloud compute copy-files <local-path> <your-instance-name>:<remote-path> --zone <zone>

インスタンスにあるファイルをローカルにコピーする

gcloud compute copy-files <your-instance-name>:<remote-path> <local-path> --zone <zone>