Docker-node: How to pass flags to CMD for running node?

Created on 25 Oct 2018  路  2Comments  路  Source: nodejs/docker-node

Most helpful comment

Assuming by env file, you mean using Docker Compose or docker run -e.

In order to get env interpolation, you'll need a shell:

So either of these should work:

# option 1
CMD ["sh", "-c", "exec node --max_old_space_size=${AM_MAX_MEMORY_SIZE} server.js"]

# option 2
# since this is without json syntax, it is equivalent to the CMD with "sh -c"
CMD exec node --max_old_space_size=${AM_MAX_MEMORY_SIZE} server.js

All 2 comments

My bad! Pressed Enter and wola it posted the bug.
Alrt so per best practices https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md
it is advised to => CMD["node", "server.js"]
I need to do CMD["node", "--max_old_space_size=${AM_MAX_MEMORY_SIZE}", "server.js"]
I am passing the AM_MAX_MEMORY_SIZE in the env file along with other params.
This doesn't work at all, I have tried adding the ARGS and ENV as well.

Assuming by env file, you mean using Docker Compose or docker run -e.

In order to get env interpolation, you'll need a shell:

So either of these should work:

# option 1
CMD ["sh", "-c", "exec node --max_old_space_size=${AM_MAX_MEMORY_SIZE} server.js"]

# option 2
# since this is without json syntax, it is equivalent to the CMD with "sh -c"
CMD exec node --max_old_space_size=${AM_MAX_MEMORY_SIZE} server.js
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kingjerod picture kingjerod  路  5Comments

frankbaele picture frankbaele  路  3Comments

austinfrey picture austinfrey  路  3Comments

mtibben picture mtibben  路  3Comments

NodeGuy picture NodeGuy  路  4Comments