如何停止 gcloud docker -a 覆盖长期存在的凭据?

How to stop gcloud docker -a overwriting long-lived credentials?

我们正在使用 Google Container Registry 来存储我们的 Docker 图像。

为了授权我们的构建实例,我们在 .docker/config.json 中放置了 长期访问令牌 ,如 docs 中所述。

在有人(即某些 Makefile)使用 gcloud docker -- push ... 推送到注册表(而不是例如 docker push ...)之前,这工作得很好。 gcloud用一段时间后过期的短期凭据 替换现有的长期凭据。因此,后续构建可能会失败,具体取决于确切的时间。

我的问题:如何防止gcloud docker ...弄乱我提供的凭据?

我试过 chattr +i .docker/config.json,但这只会让 gcloud 抱怨。

来自https://cloud.google.com/sdk/gcloud/reference/docker

The gcloud docker command group wraps docker commands, so that gcloud can inject the appropriate fresh authentication token into requests that interact with the docker registry.

gcloud docker 所做的唯一一件事就是更改这些凭据,然后调用 docker CLI。如果您不希望它更改凭据,没有理由不直接调用 docker

一种解决方法可能是为您的长期凭据使用备用配置文件位置;每 https://docs.docker.com/engine/reference/commandline/cli/:

Options:
      --config string      Location of client config files (default "/root/.docker")