如何将 Docker Hub 镜像拉到 Google Cloud Run?

jea*_*rme 13 docker google-cloud-platform google-container-registry google-cloud-run

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

在此处输入图片说明

edd*_*dex 24

Google 更新了 Cloud Run 设置,现在支持开箱即用的 Docker Hub 映像。只需添加您的存储库路径(如果需要,请添加标签),无需任何区域/主机,它将从 Docker Hub 中提取。

在 Google Cloud Run 中使用 Docker Hub 映像

  • 不,图像需要托管在 dockerhub.com 上,然后您可以执行我在这里描述的操作。借助 Dockerfile,您可以使用“docker build”命令创建映像。该镜像可以推送到 DockerHub 等容器注册表。 (4认同)

gui*_*ere 18

我查看了该项目,最后我在 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
Run Code Online (Sandbox Code Playgroud)

Cloud Run 部署的技巧是:

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

因此,请使用 Cloud Run URL 而不是http://localhost:3000文档中的URL并享受!

  • 对于那些需要它的人(例如,不使用 cloud shell,而是从工作站),要从 CLI 向 GCR 进行身份验证,请使用 `gcloud auth configure-docker` (3认同)
  • 作品!太感谢了。 (2认同)