Docker使用shell脚本运行覆盖入口点,该脚本接受参数

我有入口shell脚本,它接受参数-a -b.

我有工作的docker-compose.yml文件,我用指令覆盖tomcat的入口点:

entrypoint: /usr/local/tomcat/entrypoint.sh -a param1 -b param2

什么是docker run替代品?

docker run --entrypoint "/usr/local/tomcat/entrypoint.sh -a param1 -b param2" tomcat:jre8

不起作用

我明白了:

docker: Error response from daemon: 
invalid header field value "oci runtime error: container_linux.go:247: 
starting container process caused \"exec:
\\\"/usr/local/tomcat/entrypoint.sh -a param1 -b param2\\\": 
stat /usr/local/tomcat/entrypoint.sh -a param1 -b param2: 
no such file or directory\"\n".

供参考:

docker run --entrypoint "/usr/local/tomcat/entrypoint.sh" tomcat:jre8

从Docker的角度来看,但显然脚本失败了

最佳答案
这是因为您在命令周围使用了引号.

当您运行docker run –entrypoint“/usr/local/tomcat/entrypoint.sh -a param1 -b param2”tomcat:jre8 Docker会将这些引号中的任何内容视为单个脚本文件.

从错误中可以看出:

stat /usr/local/tomcat/entrypoint.sh -a param1 -b param2: 
no such file or directory\"\n".

它正在尝试在运行之前对文件执行stat,因此它知道它是否存在.

将参数放在docker命令末尾的入口点,如下所示:

docker run --entrypoint <entrypoint.sh> <image:tag> <arg1> <arg2> <arg3>

你的命令变为:

docker run --entrypoint /usr/local/tomcat/entrypoint.sh tomcat:jre8 -a param1 -b param2 

看一下官方文档中的代码片段:

The ENTRYPOINT of an image is similar to a COMMAND because it
specifies what executable to run when the container starts

https://docs.docker.com/engine/reference/run/#/entrypoint-default-command-to-execute-at-runtime

转载注明原文:Docker使用shell脚本运行覆盖入口点,该脚本接受参数 - 代码日志