Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing PIP_EXTRA_INDEX_URL to docker build

Tags:

python

docker

pip

I am building an app that has a dependency available on a private Pypi server.

My Dockerfile looks like this:

FROM python:3.6

WORKDIR /src/mylib

COPY . ./

RUN pip install .

I want pip to use the extra server to install the dependencies. So I'm trying to pass the PIP_EXTRA_INDEX_URL environment variable during the build phase like so:

"docker build --pull -t $IMAGE_TAG --build-arg PIP_EXTRA_INDEX_URL=$PIP_EXTRA_INDEX_URL ." 

For some reason it is not working as intended, and RUN echo $PIP_EXTRA_INDEX_URL returns nothing.

What is wrong?

like image 968
Thomas Reynaud Avatar asked Jan 28 '23 06:01

Thomas Reynaud


1 Answers

You should add ARG to your Dockerfile. Your Dockerfile should look like this:

 FROM python:3.6

 ARG PIP_EXTRA_INDEX_URL 
 # YOU CAN ALSO SET A DEFAULT VALUE: 
 # ARG PIP_EXTRA_INDEX_URL=DEFAULT_VALUE

 RUN echo "PIP_EXTRA_INDEX_URL = $PIP_EXTRA_INDEX_URL"
 # you could also use braces - ${PIP_EXTRA_INDEX_URL}

 WORKDIR /src/mylib     
 COPY . ./     
 RUN pip install .

If you want to know more, take a look this article.

like image 111
Alejandro Nortes Avatar answered Jan 29 '23 20:01

Alejandro Nortes