0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

`gcloud run deploy` で `Failed to start and then listen on the port defined by the PORT environment variable.` エラー

Posted at

AWS をちょこっと触っていた人間による CloudRun への初めての deploy 作業。

image ( 呼び方あってるかわからない ) をビルドして、gcloud run deploy を実行。
以下のエラーが発生。

Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.

以下の質問・回答がドンピシャでした。

環境変数で定義されたポートを用いないといけないようです。

Dockerfile
# (略)

ENV PORT 4000
EXPOSE 4000

# (略)

node.js のエントリポイントではリッスンポートの指定を環境変数から受け取れるようにします。

index.ts
// (略)

const port = process.env.PORT || 4000;

// (略)

その後、再度ビルドしてデプロイ。

Deploying container to Cloud Run service [hoge] in project [hoge] region [asia-northeast1]
✓ Deploying... Done.
  ✓ Creating Revision...
  ✓ Routing traffic...
Done.
Service [hoge] revision [hoge-XXXX-XXX] has been deployed and is serving 100 percent of traffic.
Service URL: https://hoge-XXXXXXXXXX-an.a.run.app

無事にデプロイできました。

おしまい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?