Closed13
GCRにプッシュしたイメージをCloud Runにデプロイしたい!!!

GCRにプッシュまではOKだがCloud Runでデプロイエラー
start
. Routing traffic...
✓ Setting IAM Policy...
Deployment failed
ERROR: (gcloud.run.deploy) Cloud Run error: The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.
やりたいことゴール

コード(下記引用してる)
FROM node:14-alpine3.14
ENV PORT 8080
ENV HOST 0.0.0.0
COPY . .
RUN yarn install
EXPOSE 8080
CMD ["node","hello.js"]
const express = require('express');
const app = express();
const port = process.env.PORT || 3002;
app.get('/test' , (req,res)=>{
res.send('hello express');
});
app.listen(port, (err)=>{
if (err) {
console.error('error happened');
throw err;
}
console.log(`http://0.0.0.0:${port}/test`);
});

なんでかわからんで、下記を発見
わいもM1なのでこれかも??
Rosseta2有効にしてもう一度ローカルビルド

結果変わらず!!!なんで!!!!!

Cloud Buildつかえばうまくいくのかな?
ログ見る限りはDockerfileが悪そうに思うが何が原因かさっぱりわからん
terminated: Application failed to start: Failed to create init process: failed to load /usr/local/bin/docker-entrypoint.sh: exec format error

ローカルではビルドと実行どっちもできる

うーんやっぱりローカルでビルドしてるのがよくないみたい
これ参考にやってみよう!

こっちのが良さげ?

まあとりあえずGCRにプッシュすること目標に

これ通りにビルドファイルを作って実行
docker run gcr.io/pj_name/image_name
これでソースコードが実行されていることが確認できた

次はCloud Runだ

ちょっとコマンドでエラー見るの心折れそうだったのでUIで
でぎだ
CLIでもいけると思う

ちょっと一手間かかるけどローカルビルドはしないほうが良いね
Cloud BuildだとRosseta入れなくてもいい感じに互換してくれる
このスクラップは2022/04/16にクローズされました