docker 官方的镜像大多基于debian,但是官方源更新失败,如何更换成中国源?

docker-compose --project-name "dev_" build php
Building php
Step 1 : FROM php:5.6-fpm
 ---> a0e78ea4a88b
Step 2 : RUN apt-get update && apt-get install -y         git         libgearman-dev         libmemcached-dev         libmcrypt-dev         libfreetype6-dev         libjpeg62-turbo-dev         libpng12-dev         libmagickwand-dev         libmagickcore-dev
 ---> Running in 8181163c0190
Ign http://security.debian.org jessie/updates InRelease
Err http://security.debian.org jessie/updates Release.gpg
  Connection failed
Ign http://security.debian.org jessie/updates Release
Err http://security.debian.org jessie/updates/main amd64 Packages
  
Err http://security.debian.org jessie/updates/main amd64 Packages
  
Err http://security.debian.org jessie/updates/main amd64 Packages
  
Err http://security.debian.org jessie/updates/main amd64 Packages
  
Err http://security.debian.org jessie/updates/main amd64 Packages
  Connection failed
Err http://httpredir.debian.org jessie InRelease
  
Err http://httpredir.debian.org jessie-updates InRelease
  
Err http://httpredir.debian.org jessie Release.gpg
  Could not resolve 'httpredir.debian.org'
Err http://httpredir.debian.org jessie-updates Release.gpg
  Could not resolve 'httpredir.debian.org'
Reading package lists...
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/InRelease  

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/InRelease  

W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg  Connection failed

W: Failed to fetch http://security.debian.org/dists/jessie/updates/main/binary-amd64/Packages  Connection failed

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/Release.gpg  Could not resolve 'httpredir.debian.org'

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/Release.gpg  Could not resolve 'httpredir.debian.org'

W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package git
E: Unable to locate package libgearman-dev
E: Unable to locate package libmemcached-dev
E: Unable to locate package libmcrypt-dev
E: Unable to locate package libfreetype6-dev
E: Unable to locate package libjpeg62-turbo-dev
E: Unable to locate package libpng12-dev
E: Unable to locate package libmagickwand-dev
E: Unable to locate package libmagickcore-dev
ERROR: Service 'php' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y         git         libgearman-dev         libmemcached-dev         libmcrypt-dev         libfreetype6-dev         libjpeg62-turbo-dev         libpng12-dev         libmagickwand-dev         libmagickcore-dev' returned a non-zero code: 100
阅读 21.1k
7 个回答
#更新apt-get源 使用163的源
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
    echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && \
    echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && \
    echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && \
    echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list

要不咱用一个proxychain代理一个科学上网到1080端口,然后去请求官方源,速度也不慢。我是这么做的。

公司的话, 内部或测试机子做个私有的镜像存放服务器, 免得每次提交更新镜像都慢的蛋疼

官方的镜像大多是基于 debian:jessie 的,如果这个基础镜像经常拉取失败的话有个小窍门:

直接从国内的镜像站拉取镜像,如 daocloud ,这时拉取的镜像的名称大致是这样的: daocloud.io/library/debian:jessie,然后执行 docker tag daocloud.io/library/debian:jessie debian:jessie 就可以完成类似重命名镜像的操作(其实是给同一个镜像打了两个标签)。因为执行构建的时候会首先查找本地是否有对应名称的镜像,所以就不会从网上下载 debian 的基础镜像了

(配置 Docker 加速器) 不配置基本下载不了,墙的厉害

进入 https://dashboard.daocloud.io/ 先注册一个账号,没收费, 然后登陆后 进入个人中心,里面有 加速器,点击进入就好,然后就自己看了。里面有 Linux mac windows 的用法,

参考文章 : https://segmentfault.com/a/11...

新手上路,请多包涵

RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean
RUN apt-get update

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏