我有这个小Dockerfile
FROM alpine:3.3
RUN apk --update add python
CMD ["python", "-c", "import urllib2; response = urllib2.urlopen('https://www.python.org')"]
使用docker build -t alpine-py/01 .
构建它,然后使用docker run -it --rm alpine-py/01
运行它会创建以下输出
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/usr/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>
昨天我被最近的OpenSSL 1.0.2g版本所困扰,导致py-cryptograpy
无法编译。幸运的是,来自py-cryptography
的人几小时后在PyPI上发布了一个新版本。问题是OpenSSL中的一个函数获得了新的签名。
这可能是相关的还是我错过了什么?
答案 0 :(得分:11)
您需要安装ca-certificates才能验证公共CA签名的证书:
FROM alpine:3.3
RUN apk --no-cache add python ca-certificates
CMD ["python", "-c", "import urllib2; response = urllib2.urlopen('https://www.python.org')"]
答案 1 :(得分:1)
您需要升级Alpine,因为libssl需要使用补丁进行升级
FROM alpine:3.3
RUN apk -U upgrade && \
apk -U add python ca-certificates && \
update-ca-certificates
CMD ["python", "-c", "import urllib2; response = urllib2.urlopen('https://www.python.org')"]
apk -U升级将升级这些: