我是 Docker 和 Google Cloud 的新手。我正在尝试在 Google Cloud 上自行托管:https://github.com/movie-web/backend。 但是,我不断收到此错误:
Revision 'backend-movieweb-00006-rjg' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=80 environment variable. Logs for this revision might contain more information. Logs URL: Open Cloud Logging For more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start
我在这里设置了我正在使用的 Docker Hub 版本:
- 我也通过谷歌防火墙允许端口的入口和出口规则。
- 我还尝试添加额外的容器参数(-p 80:80)
- 我也尝试过不同的端口
如果我直接从云powershell启动它,没有其他命令,这样它就可以工作,但是它公开的公共IP需要我的谷歌帐户来验证它,所以我不能使用这种方法:
-p 80:80 \
-e MWB_POSTGRES__CONNECTION=[removed_postgrs_url] \
-e MWB_CRYPTO__SESSION_SECRET="[removed_crypto_session_secret] \
-e MWB_META__NAME=test-movie-web \
-e MWB_POSTGRES__SSL=true \
-e MWB_POSTGRES__MIGRATE_ON_BOOT=true \
-e MIKRO_ORM_MIGRATIONS_DISABLE_FOREIGN_KEYS=false \
-e MWB_SERVER__ALLOW_ANY_SITE=true \
registry-1.docker.io/techygiraffe999/backend-movieweb:1.3.1
其他设置:
Allow unauthenticated invocations Tick this if you are creating a public API or website.
All
期望它能够正常运行,给出公网IP并暴露端口80。
一些注意事项:
鉴于您已经使用过端口映射,我怀疑问题可能出在“启动”本身。我发现我的容器有时会在本地启动,但由于各种配置问题而无法在云上运行。
根据您的 Dockerfile,容器似乎正在侦听端口 81:
EXPOSE map[81/tcp:{}]
ENV MWB_SERVER__PORT=81
如果这是所需的行为,您应该将主机上的端口 80 映射到容器内的端口 81。运行命令如下所示:
docker run -p 80:81 \
-e MWB_POSTGRES__CONNECTION=[removed_postgrs_url] \
# ...more env vars
registry-1.docker.io/techygiraffe999/backend-movieweb:1.3.1
另请注意,Cloud Run 默认侦听端口 8080,因此您可能还需要检查该端口。