Starting virtualenv script rc local
<p>I'm very newbie in this field and hope someone can help me.</p>

<p>So I have a backend project which I need to launch automatically when the computer switches on (I really don't care how, using systemd or rc.local, my boss told me rc.local, but I guess either will do). I just need to start a docker container, then start my virtualenv and then run the project.</p>

<p>So far I've tried this at <code>/etc/rc.local</code></p>

<p><code>docker start cassandratt #my docker container
sleep 20 #an ugly hack to give time for the container to start
cd /home/backend/
. venv/bin/activate
. /run.py</code></p>

<p>It doesn't work, but the docker container starts, so I guess the problem is around virtualenv or python, I really don't know as I don't have any experience on this field. </p>

<p>Any idea on how I could accomplish it? </p>

<p>Thanks in advance</p>

<p><strong>Edit:</strong></p>

<p>Following Samer's guidance I tried creating a folder after activating the virtualenv and it created fine, so I suppore the problem is trying to execute run.py, perhaps loading the virtualenv's python? </p>

<p><code>docker start cassandratt #my docker container
cd /home/backend/
. venv/bin/activate
mkdir test #folder created fine
. /run.py
mkdir test2 #folder not created</code></p>

<p>So, partially, the solution seems to set some variables instead of accesing them directly. At least this worked for me. Thanks Samer for giving us a big tip :)</p>

<p><code>HOME=/home/backend #the project path
docker start container
. $HOME/venv/bin/activate #activates the virtualenv of the project
/usr/bin/env python $HOME/run.py &amp; #runs the run.py through virtualenv's python                  and runs it in the background
exit 0</code></p>

python linux virtualenv boot