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?

【Docker buildxトラブルシューティングTips】QEMUでDockerfileをクロスコンパイル時にSegmentation fault (core dumped)が発生する時の対処方法

Last updated at Posted at 2025-05-20

はじめに

Docker buildxコマンドを使って、クロスコンパイルすると、Segmentation fault (core dumped)が頻発する際の対処方法を紹介する。Segmentation fault (core dumped)は、再現性がなく、発生したりしなかったりする。

動作確認環境

  • Ubuntu 22.04 x86_64
  • Docker
    docker version
    Client: Docker Engine - Community
     Version:           28.1.1
     API version:       1.49
     Go version:        go1.23.8
     Git commit:        4eba377
     Built:             Fri Apr 18 09:52:18 2025
     OS/Arch:           linux/amd64
     Context:           default
    
    Server: Docker Engine - Community
     Engine:
      Version:          28.1.1
      API version:      1.49 (minimum version 1.24)
      Go version:       go1.23.8
      Git commit:       01f442b
      Built:            Fri Apr 18 09:52:18 2025
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.7.27
      GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
     runc:
      Version:          1.2.5
      GitCommit:        v1.2.5-0-g59923ef
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0
      ```
    
    

原因

エラー発生時のクロスコンパイル時に利用していたQEMUは、multiarch/qemu-user-staticであった。buildxが出た当時は、こちらが推奨されていたが、既に開発が終了している。QEMUを変更するとエラーが解消されたため、QEMUが古かったことが原因と考えられる。

対策

QEMUを、公式ドキュメントの推奨のtonistiigi/binfmtに変更する。執筆時点のbinfmtの最新版は、deploy/v9.2.2-52なので、こちらを適用する。

Dockerビルド実行前に、QEMUの設定をBefore(変更前)からAfter(変更後)に変更する。

Before(変更前)
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
After(変更後)
docker run --privileged --rm tonistiigi/binfmt:qemu-v9.2.2-52 --uninstall qemu-*
docker run --privileged --rm tonistiigi/binfmt:qemu-v9.2.2-52 --install all

結果

QEMUを変更したところ、Segmentation fault (core dumped)が発生しなくなった。

まとめ

Docker buildxコマンドを使って、クロスコンパイルすると、Segmentation fault (core dumped)が頻発する際の対処方法を紹介した。QEMUを最新のものに変更することでSegmentation fault (core dumped)が発生しなくなった。Docker buildxコマンドでクロスコンパイルに失敗する場合に試してみてほしい。

参考

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?