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?

【AWS EC2 × Docker】docker build で「Exec format error」が出た時の対処法

Posted at

発生したエラー

AWS EC2(Ubuntu)上で docker build . を実行したところ、次のようなエラーが発生

863150K .......... .......... .......... .......... .......... 99% 18.8M 0s
863200K .......... .......... .......... .......... .......... 99% 55.7M 0s
863250K .......... .......... .......... .......... .......... 99% 82.4M 0s
863300K .......... .......... .......... .......... .......... 99% 97.0M 0s
863350K .......... .......... .......... .......... .......... 99%  388M 0s
863400K .......... .......... .......... .......... .......... 99%  368M 0s
863450K ......                                                100% 12.3T=11s
2025-04-24 00:10:22 (74.4 MB/s) - 'Anaconda3-2024.10-1-Linux-aarch64.sh' saved [884179536/884179536]

PREFIX=/opt/anaconda3

Unpacking payload ...
/opt/Anaconda3-2024.10-1-Linux-aarch64.sh: 468: /opt/anaconda3/_conda: Exec format error
The command '/bin/sh -c wget https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-aarch64.sh &&   sh /opt/Anaconda3-2024.10-1-Linux-aarch64.sh -b -p /opt/anaconda3 &&   rm -f Anaconda3-2024.10-1-Linux-aarch64.sh' returned a non-zero code: 126

Dockerfile内でAnacondaのインストーラーを使っていたらこのエラーに遭遇するかもしれません。

原因

Dockerfileで使用していたAnacondaインストーラーが**異なるCPUアーキテクチャ向け(ARM)**だったため、実行に失敗しました。

Anaconda3-2024.10-1-Linux-aarch64.sh
aarch64 → ARM向け(Apple M1/M2、Gravitonなど)

EC2(t2/t3など)では x86_64 なので非対応!

結果として「Exec format error」が出た、というわけです。

解決法

① CPUアーキテクチャを確認する

まず、EC2インスタンスがどんなCPUか確認:

bash
コピーする
編集する
uname -m
x86_64 → Intel/AMD系 → この場合、aarch64版はNG!

aarch64 → ARM系

② Dockerfile を修正

aarch64.sh を x86_64.sh に変えて、正しいアーキテクチャ用インストーラーを使います。

dockerfile
コピーする
編集する
RUN wget https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh &&
bash Anaconda3-2024.10-1-Linux-x86_64.sh -b -p /opt/anaconda3 &&
rm -f Anaconda3-2024.10-1-Linux-x86_64.sh

③ 再ビルド

Dockerイメージを再ビルドして完了!
docker build .

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?