简体   繁体   English

入口点脚本中的 Docker exec 命令失败

[英]Docker exec command in entrypoint script fails

Following the suggestion on Execute a script before CMD (I needed to clear out a temp dir before a container is re-launched, to fix a bug), I modified my docker file from using a CMD, to entrypoint as follows:按照在 CMD 之前执行脚本的建议(我需要在重新启动容器之前清除临时目录以修复错误),我将我的 docker 文件从使用 CMD 修改为入口点,如下所示:

ENTRYPOINT ["/app/entrypoint.sh", "/usr/bin/java -Dlog4j.configurationFile=/app/resources/LINUX/${LOG4J_FILE} -Dpa.config=/app/resources/LINUX/${CONFIG_FILE} -jar /app/app.jar"]

and in entrypoint file end after the rm -rf command:并在 rm -rf 命令之后的入口点文件结束:

exec "$@"

But docker is unable to launch the container, it exits, container log shows:但是docker无法启动容器,它退出了,容器日志显示:

+ exec '/usr/bin/java -Dlog4j.configurationFile=/app/resources/LINUX/${LOG4J_FILE} -Dpa.config=/app/resources/LINUX/${CONFIG_FILE} -jar /app/app.jar' /app/entrypoint.sh: line 7: /usr/bin/java -Dlog4j.configurationFile=/app/resources/LINUX/${LOG4J_FILE} -Dpa.config=/app/resources/LINUX/${CONFIG_FILE} -jar /app/app.jar: No such file or directory - what does this mean? + exec '/usr/bin/java -Dlog4j.configurationFile=/app/resources/LINUX/${LOG4J_FILE} -Dpa.config=/app/resources/LINUX/${CONFIG_FILE} -jar /app/app.jar' /app/entrypoint.sh: line 7: /usr/bin/java -Dlog4j.configurationFile=/app/resources/LINUX/${LOG4J_FILE} -Dpa.config=/app/resources/LINUX/${CONFIG_FILE} -jar /app/app.jar: No such file or directory - 这是什么意思? what is wrong?怎么了?

You need to break the JSON-array-format command line into separate words.您需要将 JSON-array-format 命令行分解为单独的单词。 Since you've explicitly told Docker that the “command” part of this is a single word, it's looking for a binary file in /usr/bin named java -Dlog4j.configurationFile=... , with the spaces and options and all as part of the filename, and not finding it.由于您已明确告诉 Docker,其中的“命令”部分是一个单词,因此它正在/usr/bin java -Dlog4j.configurationFile=...名为java -Dlog4j.configurationFile=...的二进制文件,其中包含空格和选项等文件名的一部分,但没有找到。

You typically don't want to embed the command you want to run in ENTRYPOINT , especially if you're using this wrapper layout.您通常不想在ENTRYPOINT嵌入要运行的命令,尤其是在使用此包装器布局时。 Make ENTRYPOINT just be the name of the script ending in exec "$@" ;使ENTRYPOINT成为以exec "$@"结尾的脚本名称; it must use JSON-array syntax.它必须使用 JSON 数组语法。 Make CMD be the actual command you want to run, in whichever syntax is more convenient.使CMD成为您想要运行的实际命令,使用更方便的语法。 (If you're trying to expand environment variables, the shell-oriented syntax might be better.) (如果您尝试扩展环境变量,面向 shell 的语法可能会更好。)

ENTRYPOINT ["/app/entrypoint.sh"]
CMD /usr/bin/java \
  -Dlog4j.configurationFile=/app/resources/LINUX/${LOG4J_FILE} \
  -Dpa.config=/app/resources/LINUX/${CONFIG_FILE} \
  -jar /app/app.jar

I've found this pattern to be sufficiently common and useful that I'd generally recommend using ENTRYPOINT only for this sort of wrapper script;我发现这种模式非常普遍和有用,因此我通常建议仅将ENTRYPOINT用于此类包装器脚本; prefer putting the command to start your application as CMD , even if you don't have an entrypoint wrapper.更喜欢将启动应用程序的命令作为CMD ,即使您没有入口点包装器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM