title: Threads: unable to open database file with sqlite3 inside docker
body: <p>I am using a Flask application run by gunicorn which works fine if I run it directly on my server but fails if I run it inside Docker with the error</p>
  <pre><code>Exception in thread Thread-1:
  Traceback (most recent call last):
    File &quot;/usr/lib64/python3.8/threading.py&quot;, line 932, in _bootstrap_inner
      self.run()
    File &quot;/usr/lib64/python3.8/threading.py&quot;, line 870, in run
      self._target(*self._args, **self._kwargs)
    File &quot;/opt/app-root/src/backend.py&quot;, line 242, in runAlertManager
      db = get_db()
    File &quot;/opt/app-root/src/backend.py&quot;, line 29, in get_db
      db = g._database = sqlite3.connect(DATABASE)
  sqlite3.OperationalError: unable to open database file
  </code></pre>
  <p>If I get a cli inside the docker container I can use the sqlite3 client just fine on that file. If I remove the Threading part it also works fine just not sure why it does work directly but not in Docker</p>
  <p>Simplified I have something like this</p>
  <pre><code>from threading import Thread
  from time import sleep
  from flask import g, Flask, request, jsonify, current_app
  app = Flask(__name__)
  
  def get_db():
      db = getattr(g, '_database', None)
      if db is None:
          print(DATABASE)
          db = g._database = sqlite3.connect(DATABASE)
      return db
  
  def runAlertManager(app):
      '''
      Runs AlertManager in a separate process
      '''
      with app:
          db = get_db()
          while True:
            #do something
            sleep(10)
  
  x = Thread(target=runAlertManager, args=(app.app_context(), ))
  x.start()
  </code></pre>