LoginSignup
53
26

More than 1 year has passed since last update.

docker build時にapt-get updateでPackages Not Found

Posted at

事象

ruby:2.4.1-slim-stretch のDockerイメージビルド時に以下のエラーが発生。
エラーは先頭でビルドに必要なパッケージ群をインストールする箇所で発生していた。

Dockerfile
RUN apt-get update && apt-get install XXXXX
$ docker build XXXX
:
E: Failed to fetch http://security.debian.org/dists/stretch/updates/main/binary-arm64/Packages  404  Not Found
E: Failed to fetch http://deb.debian.org/debian/dists/stretch/main/binary-arm64/Packages  404  Not Found
E: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/main/binary-arm64/Packages  404  Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.
ERROR: executor failed running [/bin/sh -c apt-get update && apt-get install XXXXX]: exit code: 100

原因

ruby:2.4.1-slim-stretch のLinux OSディストリビューションであるDebianのバージョンが古く、パッケージのインデックスファイルの置き場所が変更されてしまっているため。

/etc/apt/sources.list
deb http://deb.debian.org/debian stretch main
deb http://deb.debian.org/debian stretch-updates main
deb http://security.debian.org stretch/updates main

対処方法(暫定)

デッドリンクになっているライブラリ一覧の向き先をアーカイブのホストに変更すればOK。
/etc/apt/sources.list の記述を上書きする。

/etc/apt/sources.list
deb http://deb.debian.org/debian stretch main
deb http://deb.debian.org/debian stretch-updates main
deb http://security.debian.org stretch/updates main

↓↓↓↓↓

/etc/apt/sources.list
deb http://archive.debian.org/debian/ stretch main
deb http://archive.debian.org/debian-security stretch/updates main

つまり、以下のようにDockerfileのRUNを書き換えれば良い。

Dockerfile
RUN apt-get update && apt-get install XXXXX

↓↓↓↓↓

Dockerfile
RUN echo "deb http://archive.debian.org/debian/ stretch main" > /etc/apt/sources.list \
    && echo "deb http://archive.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list \
    && apt-get update \
    && apt-get install XXXX

対処方法(恒久)

利用しているDocker ImageのDebianバージョンが古いことが根本原因のため、Rubyのパッチバージョンを上げてDebianバージョンも安定版に上げる。
これにより、アーカイブ参照は(当面は)不要となる。

Debian:bullseye / Ruby:2.7.7

※動作確認は必要

53
26
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
53
26