【问题标题】:Gcloud and docker confusionGcloud 和 docker 混淆
【发布时间】:2021-11-06 14:53:55
【问题描述】:

我对 gcloud verse docker 的步骤非常迷茫。我有一些构建 docker 镜像的 gradle 代码,我在这样的镜像中看到它

(base) Deans-MacBook-Pro:stockstuff-all dean$ docker images
REPOSITORY                         TAG       IMAGE ID       CREATED          SIZE
gcr.io/prod-stock-bot/stockstuff   latest    b041e2925ee5   27 minutes ago   254MB

我不清楚我是否需​​要运行 docker push,或者我是否可以直接使用 gcloud run deploy,所以我尝试像这样使用 docker push

(base) Deans-MacBook-Pro:stockstuff-all dean$ docker push gcr.io/prod-stockstuff-bot/stockstuff
Using default tag: latest
The push refers to repository [gcr.io/prod-stockstuff-bot/stockstuff]
An image does not exist locally with the tag: gcr.io/prod-stockstuff-bot/stockstuff

我不知道为什么当我继续列出图像时它说图像在本地不存在。我继续尝试 gcloud run deploy 像这样

(base) Deans-MacBook-Pro:stockstuff-all dean$ gcloud run deploy stockstuff --project prod-stock-bot --region us-west1 --image gcr.io/prod-stockstuff-bot/stockstuff --platform managed
Deploying container to Cloud Run service [stockstuff] in project [prod-stock-bot] region [us-west1]
X Deploying... Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
  X Creating Revision... Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.
  . Routing traffic...
Deployment failed
ERROR: (gcloud.run.deploy) Image 'gcr.io/prod-stockstuff-bot/stockstuff' not found.

我将这一切作为一个游乐场项目进行,似乎甚至无法启动并运行云运行部署。

我尝试了the spring example,但它甚至没有创建一个 docker 映像,并且无论如何它都失败了

ERROR: (gcloud.run.deploy) Missing required argument [--image]: Requires a container image to deploy (e.g. `gcr.io/cloudrun/hello:latest`) if no build source is provided.

【问题讨论】:

  • 您在 GCR 控制台上看到容器了吗? console.cloud.google.com/gcr 可能是您刚刚命名了一个类似该 URL 的容器,并且从未推送到 GCR 存储库。
  • 我真的建议你不要使用latest 标签,顺便说一句。有一天它咬你一口
  • 嗨@Dean Hiller,当您在本地系统中列出图像时,我看不到此图像“gcr.io/prod-stockstuff-bot/stockstuff”。使用此名称“gcr.io/prod-stock-bot/stockstuff”标记图像并重新运行 gcloud run 命令。
  • 谢谢@Sri,你成功了。我一直想念我有一个错字!!

标签: docker gcloud google-cloud-run


【解决方案1】:

您需要注意 3 个上下文。

  1. 您的本地站点,带有您自己的码头。
  2. 基于云的谷歌容器注册:https://console.cloud.google.com/gcr/
  3. 来自 GCP 的 Cloud Run 产品

所以步骤是:

  1. 在本地或使用 Cloud Build 构建您的容器

  2. 将容器推送到 GCR 注册表, 如果你在本地构建

    docker 标签busybox gcr.io/my-project/busybox docker push gcr.io/my-project/busybox

  3. 部署到 Cloud 从 Google Cloud Repository 运行容器。

【讨论】:

    【解决方案2】:

    当图像未在本地/正确标记时会发生此错误。您可以尝试的步骤。

    • 在本地创建名称为 stockstuff 的图像(创建时不要在其前面加上 gcr 和项目名称)。
    • 使用 gcr 存储库详细信息标记图像
    $ docker tag stockstuff:latest gcr.io/prod-stockstuff-bot/stockstuff:latest
    
    • 检查您的映像是否在 GCR 中可用(必须在此处查看您的映像,然后才能在 cloudrun 上部署)。
    $ gcloud container images list --repository gcr.io/prod-stockstuff-bot
    
    • 如果您可以在列表中看到您的图像,接下来您可以尝试使用以下命令(与您一样)部署 gcloud run。
    gcloud run deploy stockstuff --project prod-stock-bot --region us-west1 --image gcr.io/prod-stockstuff-bot/stockstuff --platform managed
    

    【讨论】:

    • 问题是一个该死的错字,花了很长时间才弄清楚 gcr.io/prod-stock-bot/stockstuff 与 gcr.io/prod-stockstuff-bot/stockstuff - 错字很有趣跨度>
    【解决方案3】:

    当您在本地系统中列出图像时,我看不到此图像 gcr.io/prod-stockstuff-bot/stockstuff。您可以通过使用此图像gcr.io/prod-stock-bot/stockstuff 标记该图像来创建一个新图像,然后重新运行 gcloud run 命令。

    【讨论】:

      猜你喜欢
      • 2020-09-04
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      • 2021-04-10
      • 2011-12-04
      • 2016-01-12
      • 2013-01-02
      • 2018-06-01
      相关资源
      最近更新 更多