title: Missing environment variables on running python cronjob in Docker
body: <p>I'm running a python script inside a docker container using crontab. Also, I set some environment variables (as database host, password, etc.) in <code>.env</code> file in the project's directory. If I run the script manually inside the container (<code>python3 main.py</code>) everything is working properly. But when the script is run by crontab the environment variables are not found (<code>None</code>).
  I have the following setup:</p>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM ubuntu:latest
  
  RUN apt-get update -y
  RUN apt-get -y install cron
  RUN apt-get install -y python3-pip python-dev
  
  WORKDIR /home/me/theservice
  COPY . .
  
  RUN chmod 0644 theservice-cron
  RUN touch /var/log/theservice-cron.log
  
  RUN chmod +x run.sh
  
  ENTRYPOINT ./run.sh
  </code></pre>
  <p><strong>run.sh</strong></p>
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  
  crontab theservice-cron
  cron -f
  </code></pre>
  <p><strong>docker-compose.yml</strong></p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3.7'
  services:
    theservice:
      build: .
      env_file:
        - ./.env
  </code></pre>
  <p><strong>theservice-cron</strong></p>
  <pre class="lang-sh prettyprint-override"><code>HOME=/home/me/theservice
  
  * * * * * python3 /home/me/theservice/main.py &gt;&gt; /var/log/theservice-cron.log 2&gt;&amp;1
  #* * * * * cd /home/me/theservice &amp;&amp; python3 main.py &gt;&gt; /var/log/theservice-cron.log 2&gt;&amp;1
  
  </code></pre>
  <p>I assumed that the cronjob is running in another directory and there the environment variables set in <code>/home/me/theservice/.env</code> are not accessible. So I tried to add <code>HOME=/home/me/theservice</code> line in the <code>theservice-cron</code> file or just to execute <code>/home/me/theservice</code> before running the script but it didn't help.</p>
  <p>In the python script, I use <code>os</code> to access environment variables</p>
  <pre class="lang-py prettyprint-override"><code>import os 
  
  print(os.environ['db_host'])
  </code></pre>
  <p>How I can fix this problem?</p>