Oleg Oleg - 2 months ago 13
Node.js Question

running nodejs app in docker with redirecting standard output to a file

i have created a Dockerfile to run a nodejs app and would like to redirect its standard output to a file like that:

CMD [ "node", "app.js", ">", "/usr/src/kuku.out", "2>&1"]

but the file kuku.out is not being created.

Answer

You need to use the "shell" form of the CMD instruction, since redirects are shell constructs:

CMD node app.js > /usr/src/kuku.out 2>&1

Or explicitly start a shell yourself:

CMD [ "sh", "-c", "node app.js > /usr/src/kuku.out 2>&1" ]

(which is basically the same as the shell form)

Comments