Activate python virtualenv in Dockerfile

后端 未结 6 1843
忘了有多久
忘了有多久 2020-12-05 02:04

I have a Dockerfile where I try to activate python virtualenv after what, it should install all dependencies within this env. However, everything still gets installed global

6条回答
  •  广开言路
    2020-12-05 02:39

    Although I agree with Marcus that this is not the way of doing with Docker, you can do what you want.

    Using the RUN command of Docker directly will not give you the answer as it will not execute your instructions from within the virtual environment. Instead squeeze the instructions executed in a single line using /bin/bash. The following Dockerfile worked for me:

    FROM python:2.7
    
    RUN virtualenv virtual
    RUN /bin/bash -c "source /virtual/bin/activate && pip install pyserial && deactivate"
    ...
    

    This should install the pyserial module only on the virtual environment.

提交回复
热议问题