1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CloudRunデプロイ時にterminated: Application failed to start: failed to load /usr/local/bin/docker-entrypoint.sh: exec format errorが発生する

Posted at

背景

Next.jsとSupabaseを使用したウェブアプリケーションをCloud Runにデプロイする際に遭遇した課題について共有します。

端末:MacBook Pro M2 Max

課題

手元でdocker builddocker pushgcloud run deployコマンドを実行しCloudRun上でリビジョンの作成まで完了するがトラフィックのルーティングが失敗してしました。

logを確認すると下記のエラーが表示されました。

ERROR 2025-22-33T04:43:28.073035984Z terminated: Application failed to start: failed to load /usr/local/bin/docker-entrypoint.sh: exec format error

解決策

docker buildコマンドに--platform linux/amd64でプラットフォームを指定

実際のコマンド

$ docker build --platform linux/amd64 -t asia-northeast1-docker.pkg.dev/hoge/bar/foo-app:latest .

学び/ポイント

アーキテクチャの違い

mac側でARM、CloudRunではLinuxでアーキテクチャに差分があったことが原因でした。
Dockerはデフォルトで実行された環境のアーキテクチャに応じてイメージを作成するため、アーキテクチャが異なるCloudRunにあげるとうまく動かなかったです。

そのため、Apple SiliconのMacBookを使用している場合は明示的にplatform linux/amd64を指定することで、Dockerに対してLinuxのamd64でビルドする必要があります。

改善の余地

platform linux/amd64を加えることでdocker buildコマンドの時間が8分以上かかるようになってしまいました。(加える前は5分未満で完了した)。

参考情報

Deploy Next.js Supabase App to Cloud Run using Artifact Registry and Secrets Manager
CloudRunのデプロイに失敗した時のメモ(failed to load /bin/sh: exec format error)
docker build --platform=linux/amd64 fails: ERROR: failed to solve: no match for platform in manifest

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?