您是否考虑使用Squid 代理?
编辑:如果您不想访问上面的官方网站,这里是 Squid 代理(基于 Debian)的快速设置指南。
apt-get install squid-deb-proxy
然后更改Squid配置,通过打开来创建更大的空间
/etc/squid/squid.conf
将 #cache_dir ufs /var/spool/squid
替换为 cache_dir ufs /var/spool/squid 10000 16 256
,这样就有了 10,000 MB 的缓存空间。
然后在 Dockerfile 中指定代理地址,以下是一个带有 Squid 代理的 Dockerfile 示例。
适用于 yum 和 apt-get 的发行版:
适用于 apt-get 的发行版
`FROM debian
RUN apt-get update -y && apt-get install net-tools
RUN echo "Acquire::http::Proxy \"http://$( \
route -n | awk '/^0.0.0.0/ {print $2}' \
):8000\";" \ > /etc/apt/apt.conf.d/30proxy
RUN echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> \
/etc/apt/apt.conf.d/30proxy
CMD ["/bin/bash"]`
基于yum的发行版
`FROM centos:centos7
RUN yum update -y && yum install -y net-tools
RUN echo "proxy=http://$(route -n | \
awk '/^0.0.0.0/ {print $2}'):3128" >> /etc/yum.conf
RUN sed -i 's/^mirrorlist/#mirrorlist/' \
/etc/yum.repos.d/CentOS-Base.repo
RUN sed -i 's/^#baseurl/baseurl/' \
/etc/yum.repos.d/CentOS-Base.repo
RUN rm -f /etc/yum/pluginconf.d/fastestmirror.conf
RUN yum update -y
CMD ["/bin/bash"]`
假设您在AWS注册表中安装了Squid代理,只有第一次构建才会从互联网获取数据,其余的(另一个服务器)构建应该来自Squid代理缓存。
这种技术基于书籍《Docker实践》中的技术57,标题为“设置软件包缓存以加快构建”。
我认为在没有任何第三方软件的情况下,Docker中没有缓存功能。也许有,我只是不知道而已。如果我错了,请纠正我。
/tmp/tmp5o6q7_ge/secring.gpg' -2017 08:38:17 gpg:创建密钥环
/tmp/tmp5o6q7_ge/pubring.gpg' -2017 08:38:17 gpg:从 hkp 服务器 keyserver.ubuntu.com 请求密钥 DE742AFA -2017 08:38:17 gpg:/tmp/tmp5o6q7_ge/trustdb.gpg:已创建信任数据库 -2017 08:38:17 gpg:导入公钥“Launchpad PPA for MaxMind” 的公钥 DE742AFA - code_adadocker build -t myimage:latest --cache-from xxx.dkr.ecr.eu-west-1.amazonaws.com/myimage:latest .
,看看是否有帮助。 - Tarun LalwaniStep 2/37 : RUN apt-get update ---> Running in 75f813c63132 获取:1 http://security.ubuntu.com trusty-security InRelease [65.9 kB]
- code_ada