This is my project structure -
/app
/config
/controllers
/lib
/schemas
/static
/templates
/tests
__init__.py
Dockerfile
wsgi.py
This is what my Dockerfile looks like
FROM python:3.6
WORKDIR /app
COPY ./requirements.txt /.requirements.txt
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
EXPOSE 8000
ENV FLASK_APP=iterative.py
ENV FLASK_ENV=development
CMD gunicorn -b 0.0.0.0:8000 -w 4 wsgi:app
This is what my wsgi.py
looks like
from app import app
print("IS WSGI BEING RUN")
if __name__ == '__main__':
print("IS THIS RUNNING")
app.run(host="0.0.0.0", debug=True, threaded=True)
This is what my __init.py
looks like
from flask import Flask
import sys
app = Flask(__name__)
from app import routes
print("IS INIT.PY RUNNING")
This is what I do
- I run `docker build -t .
- I then run
docker run 80:8000 <app_name>
This is the output I get
[2019-04-03 09:52:09 +0530] [8547] [INFO] Starting gunicorn 19.9.0
[2019-04-03 09:52:09 +0530] [8547] [INFO] Listening at: http://0.0.0.0:8000 (8547)
[2019-04-03 09:52:09 +0530] [8547] [INFO] Using worker: sync
[2019-04-03 09:52:09 +0530] [8550] [INFO] Booting worker with pid: 8550
[2019-04-03 09:52:09 +0530] [8551] [INFO] Booting worker with pid: 8551
[2019-04-03 09:52:09 +0530] [8552] [INFO] Booting worker with pid: 8552
[2019-04-03 09:52:09 +0530] [8553] [INFO] Booting worker with pid: 8553
Note that there are no print statements coming out.
I then ssh into the docker container by doing
docker exec -it <container_id> /bin/bash
I then run (I run it at an arbitrary port just to prove that it works)
gunicorn -b 9000 -w 4 wsgi:app
Now this is the output I get
[2019-04-03 06:25:44 +0000] [30] [INFO] Starting gunicorn 19.9.0
[2019-04-03 06:25:44 +0000] [30] [INFO] Listening at: http://0.0.35.40:8000 (30)
[2019-04-03 06:25:44 +0000] [30] [INFO] Using worker: sync
[2019-04-03 06:25:44 +0000] [33] [INFO] Booting worker with pid: 33
[2019-04-03 06:25:44 +0000] [35] [INFO] Booting worker with pid: 35
/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
[2019-04-03 06:25:44 +0000] [36] [INFO] Booting worker with pid: 36
/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
[2019-04-03 06:25:44 +0000] [38] [INFO] Booting worker with pid: 38
/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
FLASK ENVIRONMENT: development
IS INIT.PY RUNNING
IS WSGI BEING RUN
IS WSGI BEING RUN
/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
FLASK ENVIRONMENT: development
IS INIT.PY RUNNING
IS WSGI BEING RUN
IS WSGI BEING RUN
FLASK ENVIRONMENT: development
IS INIT.PY RUNNING
IS WSGI BEING RUN
IS WSGI BEING RUN
FLASK ENVIRONMENT: development
IS INIT.PY RUNNING
IS WSGI BEING RUN
IS WSGI BEING RUN
I check the docker logs to make sure that the output from the container isn't just being written to a log. It is not.
Why is the behaviour different between the two cases?