文档地址 https://docs.docker.com/engine/getstarted/step_four/
按照文档步骤来的,执行该命令时报错。
试了在 Dockerfile 中加入 apt-get clean 和 sudo rm -vf /var/lib/apt/lists/*,只能减少几条 Get 报错,不能完全解决问题。
我猜测大概是 Ubuntu 的源的问题,不知道如何改 image 的源。
Docker 的设置中已添加过了 Daocloud 的加速器。
Dockerfile 文件
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
命令执行过程
$ docker build -t docker-whale .
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM docker/whalesay:latest
---> 6b362a9f73eb
Step 2/3 : RUN apt-get -y update && apt-get install -y fortunes
---> Running in c4bed37eb3f2
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 [1103 kB]
Hit http://archive.ubuntu.com trusty Release
Get:4 http://archive.ubuntu.com trusty-updates/universe Sources [220 kB]
Get:5 http://archive.ubuntu.com trusty-updates/main amd64 Packages [1197 kB]
Get:6 http://archive.ubuntu.com trusty-updates/restricted Sources [1103 kB]
Get:7 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [1197 kB]
Get:8 http://archive.ubuntu.com trusty-security/restricted Sources [1103 kB]
Get:9 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [17.0 kB]
Get:10 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [1197 kB]
Get:11 http://archive.ubuntu.com trusty-security/main Sources [2815 B]
Get:12 http://archive.ubuntu.com trusty-security/universe Sources [2815 B]
Get:13 http://archive.ubuntu.com trusty-security/main amd64 Packages [1197 kB]
Hit http://archive.ubuntu.com trusty/restricted Sources
Get:14 http://archive.ubuntu.com trusty-security/universe amd64 Packages [1197 kB]
Get:15 http://archive.ubuntu.com trusty/universe Sources [220 kB]
Get:16 http://archive.ubuntu.com trusty/main Sources [2815 B]
Get:17 http://archive.ubuntu.com trusty/main amd64 Packages [14.8 kB]
Hit http://archive.ubuntu.com trusty/restricted amd64 Packages
Get:18 http://archive.ubuntu.com trusty/universe amd64 Packages [17.0 kB]
Fetched 9920 kB in 17s (580 kB/s)
W: Size of file /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_main_source_Sources.gz is not what the server reported 2815 1334581
W: Size of file /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_universe_source_Sources.gz is not what the server reported 220105 7925687
W: Size of file /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_main_binary-amd64_Packages.gz is not what the server reported 14793 1743009
W: Size of file /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_universe_binary-amd64_Packages.gz is not what the server reported 17048 7588885
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/restricted/source/Sources Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/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-updates/restricted/binary-amd64/Packages Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/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/restricted/source/Sources Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/universe/source/Sources Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/main/binary-amd64/Packages Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/universe/binary-amd64/Packages Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/source/Sources Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/universe/source/Sources Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/binary-amd64/Packages Hash Sum mismatch
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/universe/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 && apt-get install -y fortunes' returned a non-zero code: 100
1
Eleutherios 2017-03-01 10:13:49 +08:00
……
建议你好好看下 log ,然后去 Google 搜索: “ Hash Sum mismatch ” “ apt-get ” |
2
zjb861107 2017-03-01 10:28:45 +08:00
要翻墙吧,或者用 DockerHub 镜像加速
|
3
hxsf 2017-03-01 10:40:11 +08:00
FROM docker/whalesay:latest
RUN 换国内源 RUN apt-get -y update && apt-get install -y fortunes CMD /usr/games/fortune -a | cowsay |
4
yakumo17 OP @Eleutherios 搜过的来着,顺着 stackoverflow 一条一条试,在 apt-get update 前加 apt-get clean 等,试过没有效果。在 /etc/apt/sources.list 中加入 deb 命令那些,不知道怎么找到镜像的文件位置,自己的系统是没有这个 /etc/apt/的目录···
|
5
yakumo17 OP @hxsf 找到一条这个命令
RUN sed -i 's/http:\/\/archive\.ubuntu\.com\/ubuntu\//http:\/\/mirrors\.163\.com\/ubuntu\//g' /etc/apt/sources.list 解决了 3q 还不太懂这个语句 |
6
yakumo17 OP @zjb861107 翻墙一直开着的,镜像加速用了,对下载 hub.docker.com 的有用,这里依然不行
|
7
wahyd4 2017-03-01 11:22:01 +08:00
解决 apt-get update 慢的问题,你可以试试这个: RUN sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
|
8
Eleutherios 2017-03-01 11:26:33 +08:00 1
首先,你需要知道 apt-get update 在干什么
其次,你需要知道 "Hash Sum mismatch" 意味着什么: 从 archive.ubuntu.com 更新 package 信息失败(被墙干扰) => 所以,你需要使用国内的 repo 然后,你需要知道 sed -i '******' /path/to/file 命令在干什么: 将 https://archive.ubuntu.com/ 替换为 http://mirrors.163.com/ 另外,你在主机开翻墙,很可能对 Docker 是无效的。 如果你要让 Docker 翻墙,你可以 Google socks5 docker |