在docker中运行nodejs app,将标准输出重定向到文件

时间:2022-11-02 13:53:20

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.

我创建了一个Dockerfile来运行nodejs应用程序,并希望将其标准输出重定向到这样的文件:CMD [“node”,“app.js”,“>”,“/ usr / src / kuku.out” ,“2>&1”]但是没有创建文件kuku.out。

2 个解决方案

#1


1  

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

您需要使用CMD指令的“shell”形式,因为重定向是shell结构:

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

Or explicitly start a shell yourself:

或者自己明确地启动shell:

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

(which is basically the same as the shell form)

(这与shell表格基本相同)

#2


0  

Another approach is to use one of the logging plugins to redirect application output.

另一种方法是使用其中一个日志记录插件来重定向应用程序输出。

For a contrived example using the fluentd driver:

对于使用流利驱动程序的人为例子:

#1


1  

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

您需要使用CMD指令的“shell”形式,因为重定向是shell结构:

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

Or explicitly start a shell yourself:

或者自己明确地启动shell:

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

(which is basically the same as the shell form)

(这与shell表格基本相同)

#2


0  

Another approach is to use one of the logging plugins to redirect application output.

另一种方法是使用其中一个日志记录插件来重定向应用程序输出。

For a contrived example using the fluentd driver:

对于使用流利驱动程序的人为例子: