gpt4 book ai didi

docker - docker如何使用带引号的新命令提交docker

转载 作者:行者123 更新时间:2023-12-02 19:06:52 25 4
gpt4 key购买 nike

在制作docker的过程中,我必须将其命令从/ bin / sh更改为nginx -g "daemon off;"(正是这样)。

我写:

docker commit --change="EXPOSE 80" --change='CMD ["nginx", "-g", "\"daemon off;\""]' ${arr[0]} mine/nginx_final
${arr[0]}扩展到正确的docker容器的地方。

但是,当我尝试运行此docker时,它失败并显示以下错误:
nginx: [emerg] unexpected end of parameter, expecting ";" in command line

Docker inspect也没有显示任何不良情况:
        "Cmd": [
"nginx",
"-g",
"\"daemon off;\""
],

预期,我希望 "\"daemon off;\""扩展为“关闭守护程序”;

但是我很确定 ;后面有一个 deamon off符号。这个标志去哪儿了?我该如何调试呢? (并修复)

最佳答案

Nginx无法处理包含引号的全局指令:"daemon off;"

docker commit \
--change='EXPOSE 80' \
--change='CMD ["nginx", "-g", "daemon off;"]' \
${arr[0]} \
mine/nginx_final

执行表格

CMD ["foo"] 称为执行表单。进程将通过 exec 而不是通过Shell运行。数组中的每个元素成为exec的参数。额外的 "引号将传递给nginx:
CMD ["nginx", "-g", "\"daemon off;\""]
exec('nginx', '-g', '"daemon off;"')

使用exec表单已经在不改变的情况下传递了空间,因此您需要做的是:
CMD ["nginx", "-g", "daemon off;"]
exec('nginx' '-g' 'daemon off;')

shell 形式

CMD foo 被称为 shell 形式。带有空格的全局指令参数需要在此处引用:
CMD nginx -g "daemon off;"
exec('sh', '-c', 'nginx -g "daemon off;"')
exec('nginx', '-g', 'daemon off;')

否则,解释命令的shell将在空格上分割参数,并尝试和执行带有3个参数的 nginx:
CMD nginx -g daemon off;
exec('sh', '-c', 'nginx -g daemon off;')
exec('nginx', '-g', 'daemon', 'off;')

关于docker - docker如何使用带引号的新命令提交docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49419021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com