pythondockerpip

How do I use a custom pip.conf in a docker image?


How can I configure a Docker container to use a custom pip.conf file?

This does not (seem to) work for me:

from python:3.9

COPY pip.conf ~/.config/pip/pip.conf

where pip.conf is a copy of the pip configuration that points to a proprietary package repository.


Solution

  • The problem is the ~ expansion. This is a shell feature, and it's not working in a Dockerfile.

    Just define like this, using the dest path explicitly:

    from python:3.9
    
    COPY pip.conf /root/.config/pip/pip.conf
    

    If you want to use something other than /root/.config then consider to add a WORKDIR instruction and specify paths relative to that.