10
12

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でgcloudコマンド使う

Last updated at Posted at 2019-05-05

開発環境は専らDockerで用意して、ホスト機汚したくない派です。


公式にあるようにCloud SDK のインストールから、ホスト機に直接インストールしてもいいんだけど、他の開発者にも同じ環境を強いるのが憚れるので、Dockerで使えるようにしたい。以下その方法。

質問・訂正・改善・苦情・ご意見あれば、コメントにてよろしくお願いします。

  • 2019/10/30 06:34 Dockerfile 追加

ディレクトリ構成

こんな感じ

.
├── .env  # 環境変数
├── .env.sample  # 環境変数テンプレ
├── containers  # コンテナ群
│   └── gcloud  # gcloud用コンテナ
│       └── Dockerfile
├── docker-compose.yml
└── src  #  src置き場(マウントする)

必要あらば他のコンテナを追加、srcをマウントして使う。

Dockerfile

FROM google/cloud-sdk:latest

RUN mkdir -p /src

WORKDIR /src

docker-compose.yml

version: '3'

services:
  gcloud:
    build: ${COMPOSE_PROJECT_ROOT}/containers/gcloud
    tty: true
    volumes:
      - ${COMPOSE_PROJECT_ROOT}/src:/src:cached

COMPOSE_PROJECT_ROOT は環境変数より。
mac用に相対パスで『.』、win用に絶対パスで『/c/development/project』などと指定できる余地にしてる。
(win機使わないので、これで動くか未確認だけど…)

tty で daemon化

volumes にホスト機の**./srcをコンテナの/src**にmount

起動

Docker起動後、

docker-compose up -d

簡単ポン。

利用

コンテナ内に入って使ってる。

docker-comopse exec gcloud bash
# bashじゃなくてもいいけど。。。

# ~~以降コンテナ内
gcloud -v

=> Google Cloud SDK 244.0.0
alpha 2019.04.26
app-engine-go 
app-engine-java 1.9.73
app-engine-python 1.9.85
app-engine-python-extras 1.9.85
beta 2019.04.26
bigtable 
bq 2.0.43
cbt 
cloud-datastore-emulator 2.1.0
core 2019.04.26
datalab 20190116
gsutil 4.38
kubectl 2019.04.26
pubsub-emulator 2019.04.26

主要なコンポーネント全部入り。

gcloud components list

=>Your current Cloud SDK version is: 244.0.0
The latest available version is: 244.0.0

+-------------------------------------------------------------------------------------------------------------+
|                                                  Components                                                 |
+---------------+------------------------------------------------------+--------------------------+-----------+
|     Status    |                         Name                         |            ID            |    Size   |
+---------------+------------------------------------------------------+--------------------------+-----------+
| Not Installed | Cloud Datastore Emulator (Legacy)                    | gcd-emulator             |  38.1 MiB |
| Not Installed | Cloud Firestore Emulator                             | cloud-firestore-emulator |  40.5 MiB |
| Not Installed | Cloud SQL Proxy                                      | cloud_sql_proxy          |   3.8 MiB |
| Not Installed | Emulator Reverse Proxy                               | emulator-reverse-proxy   |  14.5 MiB |
| Not Installed | Google Cloud Build Local Builder                     | cloud-build-local        |   6.0 MiB |
| Not Installed | Google Container Registry's Docker credential helper | docker-credential-gcr    |   1.8 MiB |
| Not Installed | gcloud app PHP Extensions                            | app-engine-php           |           |
| Installed     | App Engine Go Extensions                             | app-engine-go            |  56.6 MiB |
| Installed     | BigQuery Command Line Tool                           | bq                       |   < 1 MiB |
| Installed     | Cloud Bigtable Command Line Tool                     | cbt                      |   6.4 MiB |
| Installed     | Cloud Bigtable Emulator                              | bigtable                 |   5.6 MiB |
| Installed     | Cloud Datalab Command Line Tool                      | datalab                  |   < 1 MiB |
| Installed     | Cloud Datastore Emulator                             | cloud-datastore-emulator |  18.4 MiB |
| Installed     | Cloud Pub/Sub Emulator                               | pubsub-emulator          |  34.8 MiB |
| Installed     | Cloud SDK Core Libraries                             | core                     |  10.3 MiB |
| Installed     | Cloud Storage Command Line Tool                      | gsutil                   |   3.8 MiB |
| Installed     | gcloud Alpha Commands                                | alpha                    |   < 1 MiB |
| Installed     | gcloud Beta Commands                                 | beta                     |   < 1 MiB |
| Installed     | gcloud app Java Extensions                           | app-engine-java          | 104.8 MiB |
| Installed     | gcloud app Python Extensions                         | app-engine-python        |   6.0 MiB |
| Installed     | gcloud app Python Extensions (Extra Libraries)       | app-engine-python-extras |  28.5 MiB |
| Installed     | kubectl                                              | kubectl                  |   < 1 MiB |
+---------------+------------------------------------------------------+--------------------------+-----------+
To install or remove components at your current SDK version [244.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [244.0.0], run:
  $ gcloud components update

Next

GCPのアカウント認証とプロジェクトの設定

10
12
2

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
10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?