How to get pipenv running in docker?

后端 未结 3 1924
走了就别回头了
走了就别回头了 2020-12-12 15:11

Im installing pipenv in my docker:

RUN pip install pipenv
RUN cd /my/app/path/ && pipenv install
RUN cd /my/app/path/ && pipenv shell
         


        
3条回答
  •  伪装坚强ぢ
    2020-12-12 15:39

    The direct answer to this question is to not use shell, but rather run:

    CMD ["pipenv", "run", "python", "my/app.py"]
    

    If you need more flexibility, you could also pipenv run sh init.sh, which would create a shell initialized with all the pipenv environment variables.

    I actually prefer the approach C. Sweet mentions. If you can get away with prebuilding your virtual environment and simply copying it over (setting PIPENV_VENV_IN_PROJECT then using a nested FROM followed by COPY --from=builder-image), you don't need python nor pipenv nor pipenv dependencies in your final container. This greatly reduces the size of the final image.

    Dockerfile:

    WORKDIR /etc/service/
    CMD ["sh", "/etc/service/init.sh"]
    

    init.sh:

    source /etc/service/my/.venv/bin/activate
    python my/app.py
    

提交回复
热议问题