gpt4 book ai didi

docker-compose - YAML、Docker Compose、空格和引号

转载 作者:行者123 更新时间:2023-12-04 11:08:49 25 4
gpt4 key购买 nike

什么情况下必须一种是在 YAML 文件中使用引号,特别是在使用 docker-compose 时.

例如,

service:
image: "my-registry/repo:tag1"
environment:
ENV1: abc
ENV2: "abc"
ENV3: "a b c"

例如,如果需要空格,必须在环境变量周围使用引号,如 ENV3 中所述。 ?

最佳答案

经过一番谷歌搜索后,我找到了一个 blog post
正如我所理解的那样,这触及了这个问题。

我将在这里引用最重要的部分:

plain scalars:
- a string
- a string with a \ backslash that doesn't need to be escaped
- can also use " quotes ' and $ a % lot /&?+ of other {} [] stuff

single quoted:
- '& starts with a special character, needs quotes'
- 'this \ backslash also does not need to be escaped'
- 'just like the " double quote'
- 'to express one single quote, use '' two of them'

double quoted:
- "here we can use predefined escape sequences like \t \n \b"
- "or generic escape sequences \x0b \u0041 \U00000041"
- "the double quote \" needs to be escaped"
- "just like the \\ backslash"
- "the single quote ' and other characters must not be escaped"

literal block scalar: |
a multiline text
line 2
line 3

folded block scalar: >
a long line split into
several short
lines for readability

我也没有看到这样的 docker-compose 语法来设置环境变量。 Documentation建议使用简单的值,如
environment:
- ENV1=abc
- "ENV2=abc"

凡报价 "'根据我之前所说的,在这个特定示例中是可选的。

要了解如何在 env 变量中包含空格,您可以查看此 so answer

关于docker-compose - YAML、Docker Compose、空格和引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53082932/

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