如何将 Docker Hub 镜像拉取到 Google Cloud 运行?

How to pull Docker Hub image to Google Cloud Run?

我正在尝试将 Docker 图像拉入 Google 云 运行。我发现我可能需要先将它拉到 Google 容器注册表,但我能以某种方式避免它吗?另外,我宁愿直接从源头获取它以使其保持最新状态。

我看了一下这个项目,最后我在云端 运行 成功了 运行

首先,你不能在Google Container Registry or Artifact 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

云 运行 部署的技巧是:

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

那么,使用 Cloud 运行 URL 而不是文档中的 http://localhost:3000 并享受!