docker apt-get 换源问题

laradock 配置

### Environment ###########################################

# If you need to change the sources (i.e. to China), set CHANGE_SOURCE to true
CHANGE_SOURCE=true
# Set CHANGE_SOURCE and UBUNTU_SOURCE option if you want to change the Ubuntu system sources.list file.
UBUNTU_SOURCE=tsinghua

问题原因

使用laravel docker中因为众所周知的问题,会出现访问源文件失败
目前我出现问题的模块为 PHP-FPM
修改 报错相应位置源 目录 laradock/php-fpm/Dockerfile
使用以下命令替换源

RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list
RUN cat /etc/apt/sources.list
RUN rm -Rf /var/lib/apt/lists/*
RUN apt-get update

其中 cat命令 浏览文件确认源文件更替换完成

实际使用

关于镜像大小问题 减少RUN命令触发次数

RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list && rm -Rf /var/lib/apt/lists/* && apt-get update

清华源列表

在php-fpm 目录下建立sources.list

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free

直接修改源文件

COPY ./sources.list /etc/apt/sources.list

RUN cat /etc/apt/sources.list
RUN rm -Rf /var/lib/apt/lists/*
RUN apt-get update

修改后建议重新build

docker-compose build --no-cache workspace
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 10
ALMAS

推荐把四条命令拼接在一个RUN里,RUN越多镜像越大

5年前 评论

@ALMAS OK 我修改下,外面只是这样看起来简单 谢谢建议

5年前 评论

是把命令放到laradock的文件中吗

5年前 评论

@cooooler 对的 放到相应组件的Dockerfile文件就可以,根据自己情况设置就行

5年前 评论

file
增加后确实下载了 可是突然报错

E: Failed to fetch http://mirrors.aliyun.com/debian/pool/main... Hash Sum mismatch
Hashes of expected file:

  • SHA256:653083af906f433f5baf4f26ee1d1320e2251a98f20994eacc4797d34bbabaaa
  • MD5Sum:de664c460a2e4753c8a3ab2f36ec5755 [weak]
  • Filesize:86764 [weak]
    Hashes of received file:
  • SHA256:983d0414e1fc17d57b5baeac00b731fa339d7ba93b771a9c313acc949902087e
  • MD5Sum:2af9aed3dfd2f49b4f0e16839c281fb6 [weak]
  • Filesize:28453 [weak]
    Last modification reported: Wed, 25 Jan 2017 17:12:27 +0000
    E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
4年前 评论

@方圆十三 这个是源中程序缓存问题,你可以换其他的源

4年前 评论

@莫须有 是不是因为阿里云源有些包没有,造成丢包了,所以报错?

4年前 评论

@方圆十三 具体原因不是很明确,跟墙和网络环境都有关系。

4年前 评论

大概在多少行啊?

4年前 评论

file

我报的是这个错误, 不知道用楼主的方法能不能解决啊?

4年前 评论
莫须有 (楼主) 4年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!