在Docker环境中,使用php:5.4-fpm镜像时,运行apt-get update命令出现错误
使用php:5.4-fpm进行apt-get update操作时发生错误。
$ docker run -it --rm php:5.4-fpm apt-get update
Get:1 http://security.debian.org jessie/updates InRelease [44.9 kB]
Get:2 http://security.debian.org jessie/updates/main amd64 Packages [824 kB]
Ign http://httpredir.debian.org jessie InRelease
Ign http://httpredir.debian.org jessie-updates InRelease
Get:3 http://httpredir.debian.org jessie Release.gpg [2420 B]
Ign http://httpredir.debian.org jessie-updates Release.gpg
Get:4 http://httpredir.debian.org jessie Release [148 kB]
Ign http://httpredir.debian.org jessie-updates Release
Get:5 http://httpredir.debian.org jessie/main amd64 Packages [9098 kB]
Err http://httpredir.debian.org jessie-updates/main amd64 Packages
Err http://httpredir.debian.org jessie-updates/main amd64 Packages
Err http://httpredir.debian.org jessie-updates/main amd64 Packages
Err http://httpredir.debian.org jessie-updates/main amd64 Packages
Err http://httpredir.debian.org jessie-updates/main amd64 Packages
404 Not Found
Fetched 10.1 MB in 30s (327 kB/s)
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages 404 Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.
看起来/etc/apt/sources.list中的内容是旧的?所以我将会覆盖php:5.6-fpm的内容。
首先,获取5.6-fpm的内容。
$ docker run -it --rm php:5.6-fpm cat /etc/apt/sources.list
deb http://deb.debian.org/debian stretch main
deb http://security.debian.org/debian-security stretch/updates main
deb http://deb.debian.org/debian stretch-updates main
如果将这个东西写入到/etc/apt/sources.list中,可能会有警告,但总体上还是通过了。
$ docker run -it --rm php:5.4-fpm /bin/bash -c 'echo "deb http://deb.debian.org/debian stretch main" > /etc/apt/sources.list;
> echo "deb http://security.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list;
> echo "deb http://deb.debian.org/debian stretch-updates main" >> /etc/apt/sources.list;
> apt-get update;'
Get:1 http://security.debian.org stretch/updates InRelease [94.3 kB]
Ign http://deb.debian.org stretch InRelease
Get:2 http://deb.debian.org stretch-updates InRelease [91.0 kB]
Get:3 http://deb.debian.org stretch Release.gpg [2434 B]
Get:4 http://deb.debian.org stretch Release [118 kB]
Get:5 http://security.debian.org stretch/updates/main amd64 Packages [601 kB]
Get:6 http://deb.debian.org stretch-updates/main amd64 Packages [12.2 kB]
Get:7 http://deb.debian.org stretch/main amd64 Packages [9478 kB]
Fetched 10.4 MB in 11s (911 kB/s)
Reading package lists... Done
W: There is no public key available for the following key IDs:
EF0F382A1A7B6500
如果写在Dockerfile中,可以采用以下方式。
RUN echo "deb http://deb.debian.org/debian stretch main" > /etc/apt/sources.list \
echo "deb http://security.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list \
echo "deb http://deb.debian.org/debian stretch-updates main" >> /etc/apt/sources.list
RUN apt-get update
以下是一些参考网站:
https://qiita.com/rh_taro/items/40373a30ead444ae9ca7
https://github.com/tianon/docker-brew-debian/issues/31