docker build時に発生するsegmentation fault問題の解決法
エラーの内容
この前勉強始めたオライリーのDockerの本に書かれたサンプルコードを動かそうと思ったら、こんな感じで怒られました。
E: Method http has died unexpectedly! E: Sub-process http received a segmentation fault.
セグフォ…だと?
環境
現在はVirtual Box上でDebian(buster)動かしています。
- ホスト(on VM)側の環境
# cat /etc/debian_version 10.0 # uname -a Linux debian 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5+deb10u1 (2019-07-19) x86_64 GNU/Linux
- Dockerfile
FROM debian:wheezy RUN apt-get update && apt-get install -y cowsay fortune
- 実行結果
# docker build -t test/cowsay-dockerfile . Sending build context to Docker daemon 2.048kB Step 1/2 : FROM debian:wheezy ---> 10fcec6d95c4 Step 2/2 : RUN apt-get update && apt-get install -y cowsay fortune ---> Running in effe7b2ddc64 E: Method http has died unexpectedly! E: Sub-process http received a segmentation fault. The command '/bin/sh -c apt-get update && apt-get install -y cowsay fortune' returned a non-zero code: 100
このエラーには解決方法が2つあります。
解決方法1 ~バージョンアップしたイメージの利用~
おすすめはこちら。
debian:wheezyは古くサポートも切れているので、ベースイメージをdebian:jessie以降に変更する。
- Dockerfile
FROM debian:jessie RUN apt-get update && apt-get install -y cowsay fortune
- 実行結果
# docker build -t test/cowsay-dockerfile . Sending build context to Docker daemon 2.048kB Step 1/2 : FROM debian:jessie jessie: Pulling from library/debian e7a7e6031030: Pull complete Digest: sha256:a8ae3c5129fb2e10a62b5c059a24308831508c44018c24ccda2e4fc6fd7cdda7 Status: Downloaded newer image for debian:jessie ---> 652b7a59e393 Step 2/2 : RUN apt-get update && apt-get install -y cowsay fortune ---> Running in 0506b2497a2e Get:1 http://security.debian.org jessie/updates InRelease [44.9 kB] ~中略~ Processing triggers for libc-bin (2.19-18+deb8u10) ... Processing triggers for systemd (215-17+deb8u13) ... Removing intermediate container 0506b2497a2e ---> a572a52e3ebd Successfully built a572a52e3ebd Successfully tagged test/cowsay-dockerfile:latest
これで、解決しました。
解決方法2 ~vsyscallを有効にする~
これが起こる原因は最新のカーネルではvsyscallが無効になっていることに起因するそうです。
なので、これを有効化すれば動くはず。
こちらのポストにも書かれていますね。
有効にするためには以下の手順を踏みます。
-
/etc/default/grub
書き換え
GRUB_DEFAULT=0 GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` # GRUB_CMDLINE_LINUX_DEFAULT="quiet" これをコメントアウト GRUB_CMDLINE_LINUX_DEFAULT="quiet vsyscall=emulate" # こっちを追記 GRUB_CMDLINE_LINUX=""
update-grub
の実行
# update-grub
再起動
Dockerfileからdocker build
# docker build -t test/cowsay-dockerfile . Sending build context to Docker daemon 2.56kB Step 1/2 : FROM debian:wheezy ---> 10fcec6d95c4 Step 2/2 : RUN apt-get update && apt-get install -y cowsay fortune ---> Running in 4bafae22c8fd Ign http://security.debian.org wheezy/updates Release.gpg Ign http://security.debian.org wheezy/updates Release Err http://security.debian.org wheezy/updates/main amd64 Packages Ign http://deb.debian.org wheezy Release.gpg Ign http://deb.debian.org wheezy-updates Release.gpg Err http://security.debian.org wheezy/updates/main amd64 Packages Err http://security.debian.org wheezy/updates/main amd64 Packages (中略) Err http://deb.debian.org wheezy/main amd64 Packages 404 Not Found Err http://deb.debian.org wheezy-updates/main amd64 Packages 404 Not Found W: Failed to fetch http://security.debian.org/debian-security/dists/wheezy/updates/main/binary-amd64/Packages 404 Not Found W: Failed to fetch http://deb.debian.org/debian/dists/wheezy/main/binary-amd64/Packages 404 Not Found W: Failed to fetch http://deb.debian.org/debian/dists/wheezy-updates/main/binary-amd64/Packages 404 Not Found E: Some index files failed to download. They have been ignored, or old ones used instead. The command '/bin/sh -c apt-get update && apt-get install -y cowsay fortune' returned a non-zero code: 100
はい、segmentation faultは消えたね。
あれ、でも404がでる…。なんか間違えたかな?
これはリンクが古くなっているためだそうで以下のQiitaのページを参照してください。
結論
wheezyはもう使わないほうがいい。