我在代理后面,无法构建Docker映像.
我尝试使用FROM ubuntu,FROM centos和FROM Alpine,但是apt-get更新/ yum更新/ apk更新失败.
我的主机操作系统是Windows 10,因此我将Docker设置配置为使用我们的代理.
而且我还添加了
ENV http_proxy http://<PROXY>
ENV https_proxy http://<PROXY>
到我的Dockerfile,但没有成功.
我还尝试将代理设置为http://< USER>:< PASS> @< PROXY> ;,但同样没有成功.
我能够提取Docker映像.当我将代理设置设置为无代理时,我无法提取图像,因此我猜我的代理URL是正确的.
还有什么我可以尝试的想法吗?
编辑:
我还尝试将我们的DNS服务器(在ipconfig / all下列出)添加到Docker设置中,但同样没有成功.
编辑2:
我只是意识到我忘记了Ubuntu Dockerfile中的“ http://”.添加此选项后,docker build现在可以很好地用于ubuntu了-但仅适用于ubuntu.它仍然不适用于centos和高山.
这是我所有的3个Dockerfile:
Ubuntu:
FROM ubuntu
ENV http_proxy "http://<MY-PROXY>"
ENV https_proxy "http://<MY-PROXY>"
RUN apt-get update
CentOS的:
FROM centos
ENV http_proxy "http://<MY-PROXY>"
ENV https_proxy "http://<MY-PROXY>"
RUN yum update
高山:
FROM alpine
ENV http_proxy "http://<MY-PROXY>"
ENV https_proxy "http://<MY-PROXY>"
RUN apk update
错误讯息:
CentOS的:
Step 4/4 : RUN yum update
---> Running in 3deecb71823d
Loaded plugins: fastestmirror,ovl
One of the configured repositories Failed (Unknown),and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
[...]
Cannot find a valid baseurl for repo: base/7/x86_64
高山:
Step 4/4 : RUN apk update
---> Running in 76c8579734cf
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.6/main: could not connect to server (check repositories file)
WARNING: Ignoring APKINDEX.84815163.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
2 errors; 11 distinct packages available
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.6/community: could not connect to server (check repositories file)
WARNING: Ignoring APKINDEX.24d64ab1.tar.gz: No such file or directory
The command '/bin/sh -c apk update' returned a non-zero code: 2
最佳答案
对于CentOS,我必须明确地输入我的代理端口80并删除http://-part.
因此,对于CentOS,可行的解决方案如下所示(如果代理在端口80上运行):
因此,对于CentOS,可行的解决方案如下所示(如果代理在端口80上运行):
FROM centos
ENV http_proxy=<My-PROXY>:80
ENV https_proxy=<My-PROXY>:80
RUN yum update
Alpine仍然不见了,它似乎需要其他行:
ENV HTTP_PROXY_AUTH=basic:*:<USER>:<PASS>
但对我不起作用.可能是因为我的密码中包含特殊字符,请参阅:https://github.com/gliderlabs/docker-alpine/issues/305
如果找到解决方案,我将更新此答案.
编辑:
对于高山,我用这个:
FROM alpine
ENV http_proxy=http://<My-PROXY>:80/
ENV https_proxy=http://<My-PROXY>:80/
RUN apk update