Docker安装PHP 5.6时deb源404错误的解决办法
搭建依赖PHP 5.6和MySQL 5.5的Docker环境失败,PHP 5.6安装报错
我要运行一个依赖PHP 5.6和MySQL 5.5的旧项目,搭建Docker环境时执行docker-compose出现错误。PHP 7.3版本能正常运行,但PHP 5.6无法安装。
错误信息
E: Failed to fetch http://deb.debian.org/debian/dists/stretch/main/binary-amd64/Packages 404 Not Found E: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/main/binary-amd64/Packages 404 Not Found E: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/main/binary-amd64/Packages 404 Not Found [IP:151.101.130.132 80] E: Some index files failed to download. They have been ignored, or old ones used instead. ERROR: Service 'app' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y git .....' returned a non-zero code: 100
使用的配置文件
docker-compose.yml
version: '2' services: # The Application app: build: context: ./ dockerfile: app.dockerfile working_dir: /var/www volumes: - ./public:/var/www - ./php.ini:/usr/local/etc/php/php.ini environment: - "DB_PORT=3306" - "DB_HOST=database" # The Web Server web: build: context: ./ dockerfile: web.dockerfile working_dir: /var/www volumes_from: - app ports: - 8080:80 # The Database database: image: mysql:5.7-debian volumes: - dbdata:/var/lib/mysql environment: - "MYSQL_DATABASE=homestead" - "MYSQL_USER=homestead" - "MYSQL_PASSWORD=secret" - "MYSQL_ROOT_PASSWORD=secret" ports: - "33061:3306" volumes: dbdata:
app.dockerfile
FROM php:5.6.15-cli RUN apt-get update && apt-get install -y git zip unzip RUN docker-php-ext-install mysqli pdo pdo_mysql RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
web.dockerfile
FROM nginx:1.10 ADD vhost.conf /etc/nginx/conf.d/default.conf
解决方案
1. 修复PHP镜像的软件源问题
php:5.6.15-cli基于Debian Stretch系统,该版本的官方源已被归档,无法正常访问。需要替换为归档源:
修改app.dockerfile为:
FROM php:5.6.15-cli # 替换为Debian Stretch归档源 RUN sed -i 's/deb.debian.org/archive.debian.org/g' /etc/apt/sources.list && \ sed -i 's/security.debian.org/archive.debian.org/g' /etc/apt/sources.list && \ sed -i '/stretch-updates/d' /etc/apt/sources.list RUN apt-get update && apt-get install -y git zip unzip RUN docker-php-ext-install mysqli pdo pdo_mysql RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
2. 匹配MySQL版本
当前配置使用mysql:5.7-debian,但项目依赖MySQL 5.5,需修改docker-compose.yml中数据库服务的镜像:
database: image: mysql:5.5
内容的提问来源于stack exchange,提问作者Jyothi
相关产品推荐
相关产品推荐

