How to use source in docker? How to use source in docker? shell shell

How to use source in docker?


IIRC, CMD executes a separate shell so source wouldn't do what you need it to even if it did work. The source command reads and executes commands from the specified file. In the case of virtualenv it defines a bunch of environment variables, most notably, PATH. I believe that you can simply add the path of the virtual environment to the front of PATH and get a similar effect.


The activate script is just for getting an interactive shell configured for that virtualenv. You can accomplish that with a Dockerfile likeā€¦

CMD ["bash", "--rcfile", "openparty/bin/activate"]

But if you just want to run a Python command in the context of your virtualenv, it would be neater just to refer to the virtualenv's python directly:

ENTRYPOINT ["openparty/bin/python", "openparty/bin/manage.py"]

Then you can invoke commands like

docker run --rm -P openparty_image runserver

instead of having to wrestle with a shell intermediary.