【问题标题】:How to use quotes in Dockerfile CMD如何在 Dockerfile CMD 中使用引号
【发布时间】:2017-09-28 12:59:50
【问题描述】:

我的 Dockerfile 中有以下内容:

ENTRYPOINT ["/bin/wait-for", "wordpress:9000", "--"]
CMD nginx -g "daemon off;"

结果:

nginx_1      | Attempting...
nginx_1      | Command: /bin/sh -c nginx -g "daemon off;"
nginx_1      | Attempting to execute command:
nginx_1      | /bin/sh -c nginx -g "daemon off;"
ayurved_nginx_1 exited with code 0

我猜问题是引号......

我怎样才能让它执行/bin/wait-for wordpress:9000 -- nginx -g "daemon off;"

【问题讨论】:

  • 如果使用CMD的JSON形式呢? CMD ["nginx", "-g", "\"daemon off;\""]
  • 也不行
  • 这应该可以工作我猜CMD ["nginx -g 'daemon off;'"]
  • 解释发生了什么:/bin/sh -c nginx -g "daemon off;" 正在运行 nginx 作为脚本,$0 中的 -g$1 中的 daemon off。但是脚本nginx 既不看$0 $1
  • 最好的选择是根本没有 /bin/sh -c。如果您没有 shell,那么您的 argv 的其余部分将完全正确。

标签: docker dockerfile


【解决方案1】:

我在 exec 表单中使用 CMD 时遇到了类似的问题,也就是 JSON 数组。

TL;DR 似乎有一个后备机制,当 CMD 项无法正确解析时,它会引入 /bin/sh

我找不到确切的规则,但我有例子:

ENTRYPOINT ["reflex"]
CMD ["-r", ".go$"]

$ docker inspect --format '{{.Config.Cmd}}' inventories_service_dev_1 
[-r .go$]
ENTRYPOINT ["reflex"]
CMD ["-r", "\.go$"]

$ docker inspect --format '{{.Config.Cmd}}' inventories_service_dev_1 
[/bin/sh -c ["-r", "\.go$"]]

请注意上面的\

【讨论】:

    猜你喜欢
    • 2015-01-31
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 2022-01-20
    • 2020-03-09
    • 2021-02-22
    • 2022-06-11
    • 2017-08-31
    相关资源
    最近更新 更多