我花了一些时间来掌握dockerfile中ENTRYPOINT
和CMD
之间的区别。在这种情况下,我正在做一些研究,所以即使这里的想法可能不是最好的,更多的是关于如何运作。
如果我理解一切正确,那么:
ENTRYPOINT ["/bin/bash", "-l", "-c"]
CMD ["node index.js"]
应该导致该命令:
/bin/bash -l -c node index.js
正确?
我想做的是为ENTRYPOINT
创建一个基本上应该是这样的脚本:
#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"]
#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
#entry.sh
#stuff from above
$@
#dockerfile
ENTRYPOINT ["/bin/bash", "-l", "./entry.sh"]
CMD ["node", "index.js"]
答案 0 :(得分:2)
这样做并且开心:
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 /