shell - ENTRYPOINT 与 CMD 结合

标签 shell docker dockerfile

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

如果我理解正确的话,那么:

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

更新#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 /

关于shell - ENTRYPOINT 与 CMD 结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44631605/

相关文章:

bash - bash 脚本函数中的并发或锁定访问

linux - 在 Ubuntu 中永久更改主机名

linux - 旁边的文件名计算每 2 个元素的数量

docker - 为什么此正则表达式与docker自动构建中的此字符串不匹配

Docker:监控磁盘写入容器,即通过覆盖存储驱动程序

linux - 用于本地(非远程)命令执行的 ssh 隧道

docker - 发布 RaspberryPi 3b+ 和 docker compose : Installing build dependencies: finished with status 'error'

git - 我们可以更新 Docker Image 中的 git 版本吗?

php - 如何在 Google App Engine 中包含 PHP 的 MSSQL 驱动程序

docker - 如何在启动时在 docker 容器中启动服务