红联Linux门户
Linux帮助

docker build前修改ubuntu基础源

发布时间:2016-11-07 16:04:59来源:jackzlz作者:jackzlz
docker build 默认使用的是官方源。使用ubuntu官方源不但速度慢而且有的源地址无法访问导致出错。
 
以 build 官方文档示例 mydockerbuild 为例:
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 .
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-security/main/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/universe/source/Sources  Hash Sum mismatch
docker build前修改ubuntu基础源
 
修改 Dockerfile 文件,构建之前替换为网易的源
FROM docker/whalesay:latest
RUN sed -i 's/http:\/\/archive\.ubuntu\.com\/ubuntu\//http:\/\/mirrors\.163\.com\/ubuntu\//g' /etc/apt/sources.list
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
 
参考:Docker构建的时候执行网络请求很慢
docker build前修改ubuntu基础源
 
本文永久更新地址:http://www.linuxdiyf.com/linux/25804.html