我有一个奇怪的问题。我有以下 Dockerfile
:
FROM openjdk:8-jre-alpine3.8
WORKDIR /app
RUN apk --no-cache add curl bash g++ postgresql-dev python3-dev
COPY requirements.txt /app
RUN pip3 install -r requirements.txt
...
我正在使用命令 docker build -t mydocker .
构建它。它在其他计算机上构建良好,但在我的计算机上失败并出现以下错误:
Certificate did not match expected hostname:pypi.org. Certificate:{
'subject':((('organizationalUnitName',
'Domain Control Validated' ),
),
(('commonName',
'.fireonskull.com' ),
)),
'issuer':((('countryName',
'US' ),
),
(('stateOrProvinceName',
'Arizona' ),
),
(('localityName',
'Scottsdale' ),
),
(('organizationName',
'GoDaddy.com, Inc.' ),
),
(('organizationalUnitName',
'http://certs.godaddy.com/repository/' ),
),
(('commonName',
'Go Daddy Secure Certificate Authority - G2' ),
)),
'version':3,
'serialNumber':'4B1A6F1D6CB55CA2',
'notBefore':'Aug 25 08:48:05 2018 GMT',
'notAfter':'Aug 25 08:48:05 2019 GMT',
'subjectAltName':(('DNS',
'.fireonskull.com' ),
('DNS',
'fireonskull.com' )),
'OCSP': ('http://ocsp.godaddy.com/',
),
'caIssuers': ('http://certificates.godaddy.com/repository/gdig2.crt',
),
'crlDistributionPoints': ('http://crl.godaddy.com/gdig2s1-860.crl',
)
}Retrying (Retry(total=4,
connect=None,
read=None,
redirect=None,
status=None)) after connection broken by 'SSLError(CertificateError("hostname 'pypi.org' doesn't match either of '.fireonskull.com',
'fireonskull.com'",),)': /simple/pandas/
Certificate did not match expected hostname: pypi.org. Certificate: {'subject': ((('organizationalUnitName', 'Domain Control Validated'),), (('commonName', '.fireonskull.com'),)), 'issuer': ((('countryName', 'US'),), (('stateOrProvinceName', 'Arizona'),), (('localityName', 'Scottsdale'),), (('organizationName', 'GoDaddy.com, Inc.'),), (('organizationalUnitName', 'http://certs.godaddy.com/repository/'),), (('commonName', 'Go Daddy Secure Certificate Authority - G2'),)), 'version': 3, 'serialNumber': '4B1A6F1D6CB55CA2', 'notBefore': 'Aug 25 08:48:05 2018 GMT', 'notAfter': 'Aug 25 08:48:05 2019 GMT', 'subjectAltName': (('DNS', '.fireonskull.com'), ('DNS', 'fireonskull.com')), 'OCSP': ('http://ocsp.godaddy.com/',), 'caIssuers': ('http://certificates.godaddy.com/repository/gdig2.crt',), 'crlDistributionPoints': ('http://crl.godaddy.com/gdig2s1-860.crl',)} Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(CertificateError("hostname 'pypi.org' doesn't match either of '.fireonskull.com',
'fireonskull.com'",
),
)':/simple/pandas/
错误提到名称 fireonskull.com
,我听起来很熟悉。我的电脑上曾经有过这个域的 SSL 证书。
但是 docker build
与我系统上的文件有什么关系。此外,pip install
在主机操作系统上也能正常工作。请帮忙!
最佳答案
一个肮脏的 quickfix 可能是定义容器应该在构建命令中使用的 dns:
docker build --dns=1.1.1.1 -t mydocker .
但这当然不能解决根本原因。 @kichik 在他上面的评论中提到了一些事情。您需要调试名称的解析方式。我更愿意从交互式 shell 中执行此操作。
docker run -ti openjdk:8-jre-alpine3.8 sh
首先检查使用的是什么 dns 服务器:
cat /etc/resolv.conf
我得到nameserver 192.168.65.1,这是主机
现在安装 bind-tools 来获取和查询 pypi.org
apk add bind-tools
dig pypi.org
这应该会给你一个看起来像这样的答案:
; <<>> DiG 9.12.3 <<>> pypi.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55237
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;pypi.org. IN A
;; ANSWER SECTION:
pypi.org. 31 IN A 151.101.64.223
pypi.org. 31 IN A 151.101.0.223
pypi.org. 31 IN A 151.101.192.223
pypi.org. 31 IN A 151.101.128.223
;; Query time: 27 msec
;; SERVER: 192.168.65.1#53(192.168.65.1)
;; WHEN: Tue Feb 26 08:25:29 UTC 2019
;; MSG SIZE rcvd: 90
很可能您的回答会告诉您 dns 没有正确解析。要获取有关如何解析域的更多信息,请使用 +trace 选项进行挖掘
dig +trace pypi.org
这应该有望揭示是什么响应了错误的地址。
这是我的第一个回答,留在这里以备日后引用
鉴于它可以在您的主机操作系统上运行,听起来您在 docker 配置中设置了代理。
打开您的 docker 首选项并转到代理选项卡以查看。
它也可以在你的 ~/.docker/config.json 中。像这样:
{
"proxies":
{
"default":
{
"httpProxy": "http://127.0.0.1:3001",
"httpsProxy": "http://127.0.0.1:3001",
"noProxy": "*.test.example.com,.example2.com"
}
}
}
关于python - pip install 在 docker build 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54708164/