I'm behind a corporate network and can currently install Python
packages from a Dockerfile
in 2 ways.
(1) referencing the certificate
RUN pip3 install --cert=/usr/local/share/ca-certificates/zscaler-root.crt <SOME-PYTHON-PACKAGE>
(2) by adding repos/URLs to trusted hosts
RUN touch /etc/pip.conf
RUN echo "[global] \n trusted-host = pypi.python.org pypi.org files.pythonhosted.org" >> /etc/pip.conf
RUN pip3 install <SOME-PYTHON-PACKAGE>
Instead of option #2, I would prefer to set the cert globally.
RUN touch /etc/pip.conf
RUN echo "[global] \n cert=/usr/local/share/ca-certificates/zscaler-root.crt" >> /etc/pip.conf
But this does not work.
Results in a SSLError(SSLCertVerificationError.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)'))': /simple/flask/
How come option #1 can reference the cert but adding it to global config file fails ?
EDIT:
As per @phd's suggestion tried the following.
RUN pip3 config --global set global.cert /usr/local/share/ca-certificates/zscaler-root.crt
RUN pip3 config set global.cert /usr/local/share/ca-certificates/zscaler-root.crt
But no joy.
Also tried setting SSL_CERT_DIR
per https://stackoverflow.com/a/24353642/6265370.
ENV SSL_CERT_DIR="/usr/local/share/ca-certificates/"
Again no cigar.
Here the some more info
pip 21.1.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
pip3 config list -v
For variant 'global', will try loading '/etc/xdg/pip/pip.conf'
For variant 'global', will try loading '/etc/pip.conf'
For variant 'user', will try loading '/root/.pip/pip.conf'
For variant 'user', will try loading '/root/.config/pip/pip.conf'
For variant 'site', will try loading '/usr/local/pip.conf'