0

Im trying to run a Django development server and log all output to file.

My Dockerfile executes the following command:

CMD ["/srv/manage.py", "runserver", "0.0.0.0:3000", ">>", "django.log"]

It builds fine but crashes at run.

Question: How can I redirect output from CMD command to a file?

Vingtoft
  • 13,368
  • 23
  • 86
  • 135
  • Possible duplicate of [Redirecting command output in docker](http://stackoverflow.com/questions/34632959/redirecting-command-output-in-docker) – Vingtoft Nov 21 '16 at 12:09

1 Answers1

2

From this Dockerfile documentation:

Unlike the shell form, the exec form does not invoke a command shell. This means that normal shell processing does not happen. For example, CMD [ "echo", "$HOME" ] will not do variable substitution on $HOME. If you want shell processing then either use the shell form or execute a shell directly, for example: CMD [ "sh", "-c", "echo", "$HOME" ].

What your command actually does is passes the arguments "0.0.0.0:3000", ">>" and "django.log" to "/srv/manage.py". What you actually need is

CMD "/srv/manage.py runserver 0.0.0.0:3000 >> django.log"

(or)

CMD ["/srv/manage.py", "runserver 0.0.0.0:3000 >> django.log"]
Inian
  • 80,270
  • 14
  • 142
  • 161