首页 > Docker中用apt-get update报错

Docker中用apt-get update报错

刚接触docker,照着官网的例子新建image,dockerfile 如下:

FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortune
CMD /usr/game/fortune -a | cowsay

之后Build image时,发现apt-get报错。 错误如下

Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/binary-amd64/Packages Hash Sum mismatch

上面访问出错的地址并不在 /etc/apt/sources.list 中 /etc/apt/sources.list里都是使用的是cn开头的国内源。 我在docker外运行 apt-get update 并不会报错。

在docker运行的apt-get是使用不同的源吗? 我用的系统是安装在virtualbox里的 ubuntu 14.01 (64bit).
非常感谢

自己补充:
是不是因为我是更改 docker/whalesay 这个image,这个image里的/etc/apt/sources.list 和 本地的文件 不同的原因造成的? 那解决的问题方法 是不是 先给image 中apt-get添加国内源 然后 忽略报错的源。上面那个地址出错,我估计是因为公司的网络proxy造成的。


换掉源:RUN sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu\//http:\/\/mirrors.163.com\/ubuntu\//g' /etc/apt/sources.list

还有些干货:
docker的实用shell


apt-get update不需要-y
建议使用官方的镜像

我从没遇到过这种问题

【热门文章】
【热门文章】