I have this command to start a Node.js webserver like this:
node --inspect=0.0.0.0:9229 --preserve-symlinks /app/api/dist/server.js | pino-pretty
I'm placing it into a Dockerfile as the CMD
:
CMD ["node", "--inspect=0.0.0.0:9229", "--preserve-symlinks" ,"/app/api/dist/server.js", "|","pino-pretty"]
The service starts when calling docker run
but the |
is ignored so no logs are forwarded to pino-pretty
.
What am I doing wrong here?
I could put the whole command into a start.sh
or use CMD ["npm", "run", "start:prod"]
but I want to understand the core problem.
CodePudding user response:
I could put the whole command into a start.sh or use CMD ["npm", "run", "start:prod"] but I want to understand the core problem.
A pipe is a shell construct, e.g. a feature of /bin/sh
, /bin/bash
, and similar shells. When you define CMD with the json/exec syntax, you are explicitly telling docker to run the command without a shell. Therefore you need to either run the command in a script, call a shell explicitly, or run with the string/shell syntax to have docker execute the command with a shell:
CMD node --inspect=0.0.0.0:9229 --preserve-symlinks /app/api/dist/server.js | pino-pretty