When running a Django dev server with docker/fig, why is some of the log output hidden?

核能气质少年 提交于 2019-12-23 08:01:54

问题


I'm writing a Dockerfile which needs to run multiple commands as part of the CMD instruction and I thought the right way to do this would be to run a shell script with the main daemon executed via exec. Unfortunately, as part of that process some of my output (stdout? stderr? I don't know, and I don't know how to find out) gets lost.

Here's the shell script:

#!/bin/sh

python manage.py migrate
exec python manage.py runserver 0.0.0.0:8000

The idea being that the migrate command is just run once and its output shown, and then the runserver command should take over and the container runs until that process exits.

The actual problem is that the output of migrate is displayed correctly, but the immediate output of runserver is not shown. Strangely, later request logging of runserver is shown just fine.

To clarify, here's the output I expected:

[...]
No migrations to apply.
[...]
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[21/Jan/2015 16:27:06] "GET / HTTP/1.1" 200 15829

Here's what I'm getting with fig up:

[...]
No migrations to apply.
[...]
[21/Jan/2015 16:27:06] "GET / HTTP/1.1" 200 15829

I'm not even sure who's fault this is. Does the runserver command change its output depending on how it is run? Is it a problem with exec? Is it docker/fig?

As one additional data point, I noticed that I do get all the output when running the container with fig run web, but not when I do fig up, but I don't understand how that's different or relevant.

Note: sorry for the tag spam, I'll reduce the tags once I know what actually causes this effect.


回答1:


I found this old issue today using docker composer. Python logging module checks the output is a terminal so you need to add tty: true to the service. Example:

version: '2'
services:
  django:
    tty: true
    command: python -u manage.py runserver 0.0.0.0:8080
    ports:
    - "8080:8080"


来源:https://stackoverflow.com/questions/28072259/when-running-a-django-dev-server-with-docker-fig-why-is-some-of-the-log-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!