Normally, I recognize that it is better to set up a uwsgi server in addition to flask and nginx, but it is the result of doing what can be done from the current configuration.
I set up a Flask + Nginx server on Docker, but the Flask log is only output to a file, and I can't check it at the prompt for docker run or docker logs. I want to be able to do it somehow.
I will omit it considerably, but it is as follows.
Dockerfile
FROM centos:centos7
CMD ["/bin/bash", "./start.sh"]
start.sh
# !/bin/bash
uwsgi --ini=uwsgi.ini
nginx -g "daemon off;"
uwsgi.ini
daemonize = /var/log/uwsgi/uwsgi.log
In the above state, the uwsgi process will be daemonized and run, and Nginx will run as a foreground job. And all the logs are output to /var/log/uwsgi/uwsgi.log specified by daemonize.
I tried a few things, but it didn't work, and as a result, the third method worked.
I think that the console output has already been done, but check if it can be done by adding an additional stream of console output.
logger.addHandler(logging.StreamHandler())
However, daemonize seems to send what is output as standard to a file, and the contents of the added stream are also output to a file.
daemonize outputs standard output and error output to the specified file, but I dared to try to output to / dev / stdout to make it standard output. I was able to output to the console output successfully, but the log rotation function of flask goes to check the file, and an error message is constantly displayed. I searched for a way to suppress the log rotation function, but I gave up because I could not find it.
uwsgi_check_logrotate()/lseek(): Illegal seek [core/logging.c line 494]
Added tail monitoring on the startup shell. Confirm that the log can be output to both the file and the console. I need to match the output files in both start.sh and uwsgi.ini, but I was able to do it for the time being.
start.sh
#Additional part
touch /var/log/uwsgi/uwsgi.log
tail -F /var/log/uwsgi/uwsgi.log > /dev/stdout &
uwsgi --ini=uwsgi.ini
nginx -g "daemon off;"
Recommended Posts