On a Raspberry Pi 2, I used the image resin/rpi-raspbian:stretch
for running a Django application. In my Dockerfile, I Install the python3
package and start the application using ENTRYPOINT python3 manage.py runserver 0:8000
. This works, BUT when my code throws error, I got NO output using docker log
command.
I have a ImportError. When I run the command manually using docker exec
, I got the exception as expected:
pi@pi2:/etc/docker/container/pms $ sudo docker exec -it pms_app_1 python3 manage.py runserver 0:8000
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x75de3228>
[...]
ImportError: No module named 'ws4redisfrontend'
But when I run the container using docker-compose
and then open the logs, they're empty:
pi@pi2:/myapp $ sudo docker logs myapp_1
pi@pi2:/myapp $
This behaviour is only present for the manage.py
call. For example, when I extend the entrypoint like this:
ENTRYPOINT python3 -c "print('printed by python inline script')" && python3 manage.py runserver 0:8000
I see printed by python inline script in the container-logs. As a newbie in Python/Django, I can't understand why this happens. But as my print example works, it seems a Django issue, and no general problem of Python. What am I missing? Debug mode is activated in settings.py
.
By default, docker logs shows the command's STDOUT and STDERR .
docker logs
shows by default the I/O streams STDOUT and STDERR. Check if
Django logging in your settings.py
is properly configured.
For example:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler'
},
},
'loggers': {
'': { # 'catch all' loggers by referencing it with the empty string
'handlers': ['console'],
'level': 'DEBUG',
},
},
}
Source
Also worth to mention:
Changed in Django 1.10:
In older versions, log messages were written to sys.stderr instead of being handled through Python logging.
https://docs.djangoproject.com/en/1.11/ref/django-admin/#runserver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With