解决Docker的Hash Sum mismatch问题

上一篇《更换Docker的源为国内源》中,只更换了Docker的源,这里需要更换镜像中操作系统的源,本篇的案例是showdoc,在执行docker build时,会提示找不到Package,具体错误如下所示:

1
2
3
W: Failed to fetch http://ftp.cn.debian.org/debian/dists/jessie/main/binary-amd64/Packages Hash Sum mismatch

E: Some index files failed to download. They have been ignored, or old ones used instead.

解决办法就是编辑Dockerfile,修改RUN这里。
原来的Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
FROM php:5.6-apache
COPY ./ /var/www/html/

RUN \
sed -i 's#http[:]//deb[^/ ]\+#http://ftp.cn.debian.org#g' /etc/apt/sources.list && \
apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) gd mcrypt


RUN chmod -R 777 /var/www/html/

CMD ["apache2-foreground"]

修改后的Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
FROM php:5.6-apache
COPY ./ /var/www/html/

RUN \
echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib\ndeb http://mirrors.163.com/debian/ jessie-updates main non-free contrib\ndeb http://mirrors.163.com/debian/ jessie-back
ports main non-free contrib\ndeb-src http://mirrors.163.com/debian/ jessie main non-free contrib\ndeb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib\ndeb-src http://mirrors.163.com/
debian/ jessie-backports main non-free contrib\ndeb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib\ndeb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free
contrib" | tee /etc/apt/sources.list && \
apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) gd mcrypt


RUN chmod -R 777 /var/www/html/

CMD ["apache2-foreground"]

此时便可以构建Docker镜像了。构建完毕。

1
2
3
4
5
6
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

接着运行docker镜像

1
sudo docker run -d --name showdoc -p 4999:80 showdoc

提示如下:

1
7b236aaa5fc3cc6b59643748aa0f97e5442f070514611ba1db788504a3e43a39

查看进程

1
sudo docker ps

打印结果

1
2
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                  NAMES
7b236aaa5fc3 showdoc "docker-php-entrypoi 8 seconds ago Up 7 seconds 0.0.0.0:4999->80/tcp showdoc
Cco.Xyz wechat
坚持原创技术分享,您的支持将鼓励我继续创作!
0%