Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 530
Henrik Heimbuerger Avatar asked Jan 21 '15 16:01

Henrik Heimbuerger


1 Answers

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"
like image 108
ernestoalejo Avatar answered Oct 13 '22 13:10

ernestoalejo