ENTRYPOINT与CMD结合 [英] ENTRYPOINT in Combination with CMD

查看:423
本文介绍了ENTRYPOINT与CMD结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间来了解dockerfile中 ENTRYPOINT CMD 之间的区别。在这种情况下,我正在做一些研究,所以即使这里的想法可能不是最好的,也更多地是要了解它的工作原理。

I have spent some time to grasp the difference between ENTRYPOINT and CMD in a dockerfile. In this case I am doing some research, so even if the Idea here might not be the best, that is more about getting how that works.

如果我理解正确的话,而不是:

If I understood everything right, than:

ENTRYPOINT ["/bin/bash", "-l", "-c"]
CMD ["node index.js"]

应导致该命令:

/bin/bash -l -c node index.js

对吗?

我想做的是为 ENTRYPOINT 基本上应如下所示:

What I would like to do, is create a script for the ENTRYPOINT which should basically look like that:

#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 最终看起来应该像这样:

So what I would like to accomplish is: If the CMD changes all the »Steps 1 -n« should be executed and the resulting CMD should finally look like:

/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-可以正常工作,但是我不是个好主意



UPDATE #2 -- seams to work, but I don't if that's a good idea

#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 :

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中:

And in Dockerfile:

COPY entry.sh /

这篇关于ENTRYPOINT与CMD结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆