红联Linux门户
Linux帮助

源设置导致Docker镜像构建失败

发布时间:2017-06-22 11:41:23来源:linux网站作者:leolztang
编写了一个Dockerfile,主要目的是构建一个镜像,镜像默认安装了openjdk-1.8-jre,还有另外一些包(这些包里面有dev版本的,也有release版本的),Dockerfile的内容大致如下:
FROM ubuntu:16.04
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" > /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse" >> /etc/apt/sources.list \
&& apt-get update
#安装openjdk-8-jre
RUN apt-get install -y openjdk-8-jre --fix-missing
#安装其他使用的包
RUN apt-get install -y tar ubuntu-make autoconf automake build-essential libass-dev libfreetype6-dev \
libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \
libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev libx264-dev libfdk-aac-dev yasm --fix-missing
 
这段Dockerfile build没有通过,在3台机器(分别对应不同的网络环境)上测试过,只有其中一个环境是能build成功,报错的两个环境都是以下错误(有差异的原因现在也没搞清楚,搞了两三个星期了。)
Get:100 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 libllvm3.8 amd64 1:3.8-2ubuntu4 [10.3 MB]
Err:100 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 libllvm3.8 amd64 1:3.8-2ubuntu4
Hash Sum mismatch
...省略了中间一部分的日志...
Unable to correct missing packages.
E: Failed to fetch http://mirrors.aliyun.com/ubuntu/pool/main/l/llvm-toolchain-3.8/libllvm3.8_3.8-2ubuntu4_amd64.deb  Hash Sum mismatch
E: Aborting install.
The command '/bin/sh -c apt-get install -y openjdk-8-jre --fix-missing' returned a non-zero code: 100
 
这个问题困扰了好长一段时间,之后尝试了一下只使用main的源,其他的删除掉,jre能安装成功,但是后面的那些包又找不到。所以最后只能使用以下的work around方案把镜像做成了:
FROM ubuntu:16.04
#openjdk-8-jre使用了updates源之后报hash sum mismatch的错误,
#只能使用main才能安装成功,这个问题没有找到根本原因,暂时使用此解决方式
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" > /etc/apt/sources.list \
&& apt-get update
RUN apt-get install -y openjdk-8-jre --fix-missing
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" > /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse" >> /etc/apt/sources.list \
&& apt-get update
RUN apt-get install -y tar ubuntu-make autoconf automake build-essential libass-dev libfreetype6-dev \
libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \
libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev libx264-dev libfdk-aac-dev yasm --fix-missing
 
本文永久更新地址:http://www.linuxdiyf.com/linux/31669.html