Help us understand the problem. What is going on with this article?

Dockerでgcloudコマンド使う

開発環境は専ら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のアカウント認証とプロジェクトの設定

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした