11

I have this small Dockerfile

FROM alpine:3.3
RUN apk --update add python
CMD ["python", "-c", "import urllib2; response = urllib2.urlopen('https://www.python.org')"]

Building it with docker build -t alpine-py/01 . and then running it with docker run -it --rm alpine-py/01 creates the following output

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)>

Yesterday I got bitten by the recent OpenSSL 1.0.2g release, which caused py-cryptograpy to not compile. Luckily the guys from py-cryptography released a new version on PyPI a couple of hours later. The issue was that a function in OpenSSL got a new signature.

Could this be related or am I missing something?

2 Answers 2

11

You need to install ca-certificates to be able to validate signed certs by public CAs:

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
  • Thanks, this did actually save me.
    – Daniel F
    Commented Mar 3, 2016 at 4:30
1

You will need to upgrade Alpine as libssl needs to be upgraded with a patch

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 upgrade will upgrade these:

  • libcrypto1.0 (1.0.2e-r0 -> 1.0.2g-r0)
  • libssl1.0 (1.0.2e-r0 -> 1.0.2g-r0)
3
  • yes, thanks, the accepted answer already was the solution by telling me to add ca-certificates. Oh, I see, in my case the upgrade was not neccessary, but thanks for the hint, it might come in handy sometime.
    – Daniel F
    Commented Mar 24, 2016 at 17:08
  • But don't these upgrades get applied anyway? I think that when I was installing python-dev i could see that it was upgrading all used libraries as well.
    – Daniel F
    Commented Mar 24, 2016 at 17:12
  • for apk, upgrade will "Upgrade the currently installed packages". In later versions of alpine there is a patch for libssl and libcrypto that is required. When adding, i.e. apk add python-dev, it will pull in the maintainers requested dependencies for that package - which may not be the same. Commented Apr 29, 2016 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.