I am slightly modifying this Dockerfile to support my specific usecase: I need to specify my own PyPi
server, where we are publishing our internal libraries. This can normally be achieved by specifying a pip.conf
file, or by passing command line options to pip
.
I am trying with this:
FROM python:3.5
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ONBUILD COPY requirements.txt /usr/src/app/
# 1st try: set the env variable and use it implicitely. Does not work!
# ENV PIP_CONFIG_FILE pip.conf
# ONBUILD RUN pip install --no-cache-dir -r requirements.txt
# 2nd try: set once the env variable, just for this command. Does not work!
# ONBUILD RUN PIP_CONFIG_FILE=pip.conf pip install --no-cache-dir -r requirements.txt
# 3rd try: directly configure pip. Works, but these values should not be set in the Dockerfile!
ONBUILD RUN pip install --index-url http://xx.xx.xx.xx:yyyyy --trusted-host xx.xx.xx.xx --no-cache-dir -r requirements.txt
ONBUILD COPY . /usr/src/app
My pip.conf
is very simple, and works when used outside Docker
:
[global]
timeout = 60
index-url = http://xx.xx.xx.xx:yyyyy
trusted-host = xx.xx.xx.xx
Links:
Dockerfile
's ENV is documented here
pip
configuration is documented here
I have the following questions:
ENV
not working?RUN
command not working?ONBUILD
, or maybe RUN
?I was having the same problem and I managed to fix it adding this to the Dockerfile:
COPY pip.conf pip.conf
ENV PIP_CONFIG_FILE pip.conf
RUN pip install <my_package_name>
The pip.conf file has the next structure:
[global]
timeout = 60
index-url = https://pypi.org/simple
trusted-host = pypi.org
<my_server_page>
extra-index-url = https://xxxx:yyyy@<my_server_page>:<package_location>
This is the only way I found for Docker to find the package from the pypi server. I hope this solution is general and helps other people having this problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With