Passing PIP_EXTRA_INDEX_URL to docker build

Viewed 7568

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?

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.

Related