docker 文件中 PYTHONUNBUFFERED 的用途是什么? [英] What is the use of PYTHONUNBUFFERED in docker file?
问题描述
我正在观看一个 dockerize 我的 django 应用程序的教程.我不明白为什么我们在 DockerFile 中使用 PYTHONUNBUFFERED
作为环境变量.
I was watching a tutorial to dockerize my django application. I did not understand why we use PYTHONUNBUFFERED
as environment variable in DockerFile.
你能帮忙吗?
推荐答案
将 PYTHONUNBUFFERED
设置为非空值可确保 python 输出直接发送到终端(例如您的容器日志)而不是第一个缓冲并且您可以实时查看应用程序的输出(例如 django 日志).
Setting PYTHONUNBUFFERED
to a non empty value ensures that the python output is sent straight to terminal (e.g. your container log) without being first buffered and that you can see the output of your application (e.g. django logs) in real time.
这也确保没有部分输出保存在某个缓冲区中,并且在 python 应用程序崩溃的情况下永远不会写入.
This also ensures that no partial output is held in a buffer somewhere and never written in case the python application crashes.
参考资料:
- https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED
- https://alphacoder.xyz/dockerizing-django/
- https://towardsdatascience.com/how-to-contain-your-first-django-in-docker-and-access-it-from-aws-fdb0081bdf1d
这篇关于docker 文件中 PYTHONUNBUFFERED 的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!