问题描述
我正在尝试将 Docker 映像拉入 Google Cloud Run。我看到我可能需要先将它拉到 Google Container Registry,但我能以某种方式避免它吗?此外,我宁愿直接从源头获取最新信息。
解决方法
我查看了该项目,最后我在 Cloud Run 上成功运行了它
首先,您不能将图像拉到 Google Container Registry 或 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
Cloud Run 部署的诀窍是:
- 需要指定端口,不要使用默认的8080,这里是3000
- 您需要明确指定命令。默认情况下,使用入口点(
/tini
)并且容器应该没有很好地构建,因为存在权限问题。 Dockerfile 中的更多详细信息
那么,请使用 Cloud Run URL 而不是您在文档中使用的 http://localhost:3000
!