红联Linux门户
Linux帮助

Ubuntu update: Failed to fetch, Hash sum mismatch的解决

发布时间:2016-07-09 10:50:19来源:linux网站作者:heiyeah09
env: virtualbox 加载 ubuntu 16.04
根据Docker官方教程安装docker,并根据 Get Started 步骤学习,执行到 Build your own image, 出现了错误Fail to fetch , Hash sum mismatch,如下:
root@VirtulBox:/home/user/mydockerbuild# docker build -t docker-whale . 
Sending build context to Docker daemon 2.048 kB 
Step 1 : FROM docker/whalesay:latest 
—> 6b362a9f73eb 
Step 2 : RUN apt-get -y update –fix-missing && apt-get install -y fortunes 
—> Running in de18fee98f03 
Ign http://archive.ubuntu.com trusty InRelease 
Get:1 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB] 
Get:2 http://archive.ubuntu.com trusty-security InRelease [65.9 kB] 
Hit http://archive.ubuntu.com trusty Release.gpg 
Get:3 http://archive.ubuntu.com trusty-updates/main Sources [348 kB] 
Get:4 http://archive.ubuntu.com trusty-updates/restricted Sources [5217 B] 
Hit http://archive.ubuntu.com trusty Release 
Get:5 http://archive.ubuntu.com trusty-updates/main amd64 Packages [945 kB] 
Get:6 http://archive.ubuntu.com trusty-updates/universe Sources [198 kB] 
Get:7 http://archive.ubuntu.com trusty-security/restricted Sources [3920 B] 
Get:8 http://archive.ubuntu.com trusty-security/main Sources [148 kB] 
Get:9 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [23.5 kB] 
Get:10 http://archive.ubuntu.com trusty-security/main amd64 Packages [542 kB] 
Get:11 http://archive.ubuntu.com trusty-security/universe Sources [44.1 kB] 
Get:12 http://archive.ubuntu.com trusty-security/universe amd64 Packages [170 kB] 
Get:13 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [469 kB] 
Get:14 http://archive.ubuntu.com trusty/main Sources [1335 kB] 
Get:15 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [20.2 kB] 
Get:16 http://archive.ubuntu.com trusty/universe Sources [7926 kB] 
Get:17 http://archive.ubuntu.com trusty/restricted Sources [5335 B] 
Get:18 http://archive.ubuntu.com trusty/universe amd64 Packages [7589 kB] 
Get:19 http://archive.ubuntu.com trusty/restricted amd64 Packages [16.0 kB] 
Get:20 http://archive.ubuntu.com trusty/main amd64 Packages [1743 kB] 
Fetched 21.7 MB in 2min 10s (166 kB/s) 
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/source/Sources Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/binary-amd64/Packages Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/main/source/Sources Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/main/binary-amd64/Packages Hash Sum mismatch
E: Some index files failed to download. They have been ignored, or old ones used instead. 
The command ‘/bin/sh -c apt-get -y update –fix-missing && apt-get install -y fortunes’ returned a non-zero code: 100
 
网上查了一些方法,docker 更新Ubuntu时,不能正常下载源,根据网上的线索,把/etc/apt/sources.list中的 http://archive.ubuntu.com 全部替换为 http://cn.archive.ubuntu.com 即可。编辑Dockfile(参考docker–>get started–>Build your own image)文件,添加以下语句:
FROM docker/whalesay:latest
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak
RUN sed -i s:/archive.ubuntu.com:/cn.archive.ubuntu.com:g /etc/apt/sources.list
RUN cat /etc/apt/sources.list
RUN apt-get clean
RUN apt-get -y update --fix-missing && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
 
retry again, successfully ! The content showing below is my second successful execution, so maybe different from your own display.
root@VirtualBox:/home/user/mydockerbuild# docker build -t docker-whale .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM docker/whalesay:latest
---> 6b362a9f73eb
Step 2 : RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak
---> Using cache
---> ae6f1f8bb28c
Step 3 : RUN sed -i s:/archive.ubuntu.com:/cn.archive.ubuntu.com:g /etc/apt/sources.list
---> Using cache
---> e05fa6b3314b
Step 4 : RUN cat /etc/apt/sources.list
---> Using cache
---> bef9546a4272
Step 5 : RUN apt-get clean
---> Using cache
---> 5f4eea51e75d
Step 6 : RUN apt-get -y update --fix-missing && apt-get install -y fortunes
---> Using cache
---> 9b23e4613e67
Step 7 : CMD /usr/games/fortune -a | cowsay
---> Using cache
---> 872d7a86fc7b
Successfully built 872d7a86fc7b
root@VirtualBox:/home/user/mydockerbuild#
 
本文永久更新地址:http://www.linuxdiyf.com/linux/22199.html