入口与CMD结合
我花了一些时间来掌握ENTRYPOINT
和CMD
的区别。 在这种情况下,我正在做一些研究,所以即使这里的想法可能不是最好的,那更多的是要得到这个结果。
如果我理解一切正确,比如:
ENTRYPOINT ["/bin/bash", "-l", "-c"] CMD ["node index.js"]
应该导致这个命令:
/bin/bash -l -c node index.js
对?
我想要做的是为ENTRYPOINT
点创build一个脚本,基本应该是这样的:
#entry.sh #step 1 npm install #step 2 npm run watch & #step 3 compass watch & #step n #that line bothers me /bin/bash -l -c $*
所以我想完成的是:如果CMD
改变了所有的“步骤1 -n”应该被执行,并且最终的CMD
应该看起来像:
/bin/bash -l -c node index.js
相反,我得到:
node index.js: entry.sh: command not found
感谢帮助!
细节
#entry.sh npm install #more to come here /bin/bash -l -c $* #dockerfile ENTRYPOINT ["/bin/bash", "-l", "-c", "./entry.sh"] CMD ["node index.js"]
UPDATE
#entry.sh #stuff from above echo "$*" echo "$@" /bin/bash "$@" #dockerfile ENTRYPOINT ["/bin/bash", "-l", "./entry.sh"] CMD ["node", "index.js"] /usr/bin/node: /usr/bin/node: cannot execute binary file #Result: node src/index.js node src/index.js /usr/bin/node: /usr/bin/node: cannot execute binary file
更新#2 – 接缝工作,但我不,如果这是一个好主意
#entry.sh #stuff from above $@ #dockerfile ENTRYPOINT ["/bin/bash", "-l", "./entry.sh"] CMD ["node", "index.js"]
做到这一点,并开心:
ENTRYPOINT ["/entry.sh"] CMD node index.js
entry.sh:
#!/bin/bash #entry.sh #step 1 npm install #step 2 npm run watch & #step 3 compass watch & #step n exec "$@"
请确保:
chmod +x entry.sh
在Dockerfile中:
COPY entry.sh /