Docker CMD doesn't recognize pm2-runtime
The problem was that the CMD directive can't handle multiple commands out of the box.
Changing the CMD to following line fixed my issue:
CMD ["sh", "-c", "nginx && pm2-runtime start ecosystem.config.js --env $env_name"]
Docker CMD & ENTRYPOINT runs the commands implicitly with sh -c, but to chain commands and/or inject environment variables, you need to "nest" the sh -c
from docker with your own.
Are you sure you are defining the CMD as so
CMD [ "pm2-runtime", "start", "pm2.json" ]
because from what I see the error message is saying that it's looking for [pm2-runtime,
(note the [
at the start and the ,
at the end) and this is possible only if you don't have the quotes around the pm2-runtime. I would suggest you remove and type those quotes again, save the Dockerfile and try building again.
I just tested with a simple example
FROM alpineCMD [echo, "'A'" ]
And got a similar error message
/bin/sh: [echo,: not found
So I am quite certain that this is the case