LoginSignup
10
6

More than 1 year has passed since last update.

[heroku]Exec format errorというエラーの解決方法

Posted at

はじめに

本記事では、herokuへDockerコンテナをリリース後、
データベースを更新するようなコマンドを入力したところ、
Exec format errorというエラーが発生したので、解決方法を記述します。

ターミナルにて

rails-docker-mkatoはアプリ名です。

% heroku container:release web -a rails-docker-mkato
Releasing images web to rails-docker-mkato... done
% heroku run bundle exec rake db:migrate RAILS_ENV=production -a rails-docker-mkato
Running bundle exec rake db:migrate RAILS_ENV=production on ⬢ rails-docker-mkato... up, run.3205 (Free)
Error: Exec format error

ログを確認

2021-10-08T10:19:30.373656+00:00 heroku[web.1]: Starting process with command `sh /start.sh`
2021-10-08T10:19:31.572087+00:00 app[web.1]: Error: Exec format error
2021-10-08T10:19:31.715922+00:00 heroku[web.1]: Process exited with status 126
2021-10-08T10:19:31.785102+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-08T10:19:31.912808+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-08T10:19:50.024750+00:00 heroku[web.1]: Starting process with command `sh /start.sh`
2021-10-08T10:19:50.982798+00:00 app[web.1]: Error: Exec format error
2021-10-08T10:19:51.102356+00:00 heroku[web.1]: Process exited with status 126
2021-10-08T10:19:52.245987+00:00 heroku[web.1]: State changed from starting to crashed

結論

以下のサイトに倣って、コマンドを入力しましたところ解決しました。
M1 MacでHeroku containerにデプロイしたら Exec format error と出て困った話

M1 Macでx86向けのDocker Imageをビルドする

ということが必要みたいです。

コマンド入力
ユーザ名は自身が使用するusernameです。

buildしてpushするのでまあまあ時間がかかりました。

$ docker buildx build . --platform linux/amd64 -t username/example:latest
$ docker tag username/example registry.heroku.com/example/web
$ docker push registry.heroku.com/example/web
$ heroku container:release web -a example

再度コマンド入力

% heroku run bundle exec rails db:migrate RAILS_ENV=production -a rails-docker-mkato
Running bundle exec rails db:migrate RAILS_ENV=production on ⬢ rails-docker-mkato... up, run.1740 (Free)

特にエラーは起きませんでした。

以上です。

終わりに

herokuへデプロイする流れとかもしっかり理解しないといけないなと反省もしました。

以下参考サイトです。
M1 MacでHeroku containerにデプロイしたら Exec format error と出て困った話
Docker Buildx

明日も頑張ります!

10
6
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
10
6