title: how to run gunicorn on docker
body: <p>I have 2 files that depend on each other when docker is start up. 1 is a flask file and one is a file with a few functions. When docker starts, only the functions file will be executed but it imports flask variables from the flask file. Example:</p>
  
  <p><strong>Flaskfile</strong></p>
  
  <pre><code>import flask
  from flask import Flask, request
  import json
  
  _flask = Flask(__name__)
  
  @_flask.route('/', methods = ['POST'])
  def flask_main():
      s = str(request.form['abc'])
      ind = global_fn_main(param1,param2,param3)
      return ind
  
  def run(fn_main):
      global global_fn_main
      global_fn_main = fn_main
      _flask.run(debug = False, port = 8080, host = '0.0.0.0', threaded = True)
  </code></pre>
  
  <p><strong>Main File</strong></p>
  
  <pre><code>import flaskfile
  #a few functions then
  if__name__ == '__main__':
      flaskfile.run(main_fn)
  </code></pre>
  
  <p>The script runs fine without need a gunicorn. </p>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>  FROM python-flask
    ADD *.py *.pyc /code/
    ADD requirements.txt /code/
    WORKDIR /code
    EXPOSE 8080
    CMD ["python","main_file.py"]
  </code></pre>
  
  <p>In the Command line: i usally do: <code>docker run -it -p 8080:8080 my_image_name</code> and then docker will start and listen.</p>
  
  <p>Now to use gunicorn:
  I tried to modify my <code>CMD</code> parameter in the dockerfile to</p>
  
  <pre><code>["gunicorn", "-w", "20", "-b", "127.0.0.1:8083", "main_file:flaskfile"]
  </code></pre>
  
  <p>but it just keeps exiting. Am i not writing the docker gunicorn command right?</p>