Oleg Oleg - 1 year ago 66
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 Source

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)