【问题标题】:How to pull Docker Hub image to Google Cloud Run?如何将 Docker Hub 映像拉到 Google Cloud Run?
【发布时间】:2021-05-24 17:48:27
【问题描述】:

我正在尝试将 Docker 映像拉入 Google Cloud Run。我看到我可能需要先将它拉到 Google Container 注册表中,但我能以某种方式避免它吗?另外,我宁愿直接从源头获取它以使其保持最新状态。

【问题讨论】:

  • 那里可以使用普通的Docker镜像名称吗? thecodingmachine/gotenberg 还是 docker.io/thecodingmachine/gotenberg?尽管它被标记为“URL”,但图像中的示例实际上并不是标准 URL。
  • 不,这里没有雪茄。看起来他们对此有特定的要求
  • 我认为您需要先使用命令docker push gcr.io/project-name/image-name:version.0 推送它,然后尝试选择它gcr.io/project-name/image-name:version 以查看发生了什么
  • 恐怕不可能,根据cloud.google.com/run/docs/deploying#images的说法,它只支持Google Container Registry或者Google Artifact Registry
  • 这是一个开源项目。我把它放在我的待办事项中看看,这是一个有趣的案例。

标签: docker google-cloud-platform google-cloud-run google-container-registry


【解决方案1】:

看了一下项目,终于在Cloud Run上成功运行了

首先,您不能将图像拉到Google Container RegistryArtifact Registry 之外。所以你需要拉取图像,标记它并在 GCP 中推送它(你的项目与否,但在 GCP 上)

步骤如下

# Pull the image (I did it on Cloud Shell)
docker pull thecodingmachine/gotenberg:6

# Tag the image
docker tag thecodingmachine/gotenberg:6 gcr.io/<MY_PROJECT_ID>/thecodingmachine/gotenberg:6

#Push the image (no authentication issue on Cloud Shell)
docker push gcr.io/<MY_PROJECT_ID>/thecodingmachine/gotenberg:6

# Deploy on Cloud Run
gcloud run deploy --image=gcr.io/<MY_PROJECT_ID>/thecodingmachine/gotenberg:6 \
  --port=3000 --region=us-central1 --allow-unauthenticated --platform=managed \
  --command=gotenberg gotenberg

Cloud Run 部署的诀窍是:

  • 需要指定端口,不要使用默认的8080,这里是3000
  • 您需要明确指定命令。默认情况下,使用入口点(/tini)并且容器应该没有很好地构建,因为存在权限问题。更多细节在Dockerfile

那么,请使用 Cloud Run URL,而不是文档中的 http://localhost:3000,尽情享受吧!

【讨论】:

  • 哇!明天起床后马上实施——谢谢!
  • 我认为 Cloud Run 上的 tini 没有问题。 tini 应该可以正常工作。
  • @AhmetB-Google 是的,它应该可以工作。 dockerfile 执行chmod +x,当我没有指定command 参数时,我不知道为什么会在Cloud Run 日志中得到terminated: Application failed to start: Failed to create init process: failed to load /tini: permission denied。你可以试一试。
  • 有效!非常感谢。
  • 对于那些需要它的人(例如,不使用云外壳,而是从工作站),要从 CLI 向 GCR 进行身份验证,请使用 gcloud auth configure-docker
猜你喜欢
  • 2019-09-16
  • 2021-12-02
  • 2021-05-31
  • 2018-11-22
  • 1970-01-01
  • 2019-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多