英文:
Is there a default value for localstack's ${LOCALSTACK_VOLUME_DIR} variable if one is not defined?
问题
在之前的SO问题中,我问了一下在LocalStack的docker-compose文件中有哪些环境变量;例如,变量引用${LOCALSTACK_VOLUME_DIR:-./volume}
。
对于变量${LOCALSTACK_VOLUME_DIR}
:如果在环境变量中没有定义,会发生什么?
文档中提到(但我不理解/觉得含糊不清):
使用CLI启动LocalStack时,可以通过LOCALSTACK_VOLUME_DIR配置卷目录。它应该指向主机上的一个目录,然后会自动挂载到/var/lib/localstack中。默认值为:
Mac: ~/Library/Caches/localstack/volume
Linux: ~/.cache/localstack/volume
Windows: %LOCALAPPDATA%/localstack/cache/volume
- 首先,我不确定使用
docker compose
是否被视为“用于启动LocalStack的CLI”? - 其次,这是否暗示如果此值在任何地方都未提供(即无环境变量),它会用上述列表中相应主机操作系统的空/丢失值来替换?
英文:
In a previous SO question I asked what some environment variables are inside a LocalStack's docker-compose file; for example, a variable reference ${LOCALSTACK_VOLUME_DIR:-./volume}
.
For the variable ${LOCALSTACK_VOLUME_DIR}
: if this is not defined in an environment variable, what will happen?
The docs says this (but I don't understand / find it ambiguous):
> When using the CLI to start LocalStack, the volume directory can be configured via the LOCALSTACK_VOLUME_DIR. It should point to a directory on the host which is then automatically mounted into /var/lib/localstack. The defaults are:
>
> Mac: ~/Library/Caches/localstack/volume
> Linux: ~/.cache/localstack/volume
> Windows: %LOCALAPPDATA%/localstack/cache/volume
-
Firstly, I'm not sure if using
docker compose
is considered "CLI to start LocalStack"? -
Secondly, is this suggesting that if this value is not provided anywhere (ie. no env var) then it will replace the empty/missing value, with one of those from the list above ☝🏻 based on the host OS?
答案1
得分: 2
The ${LOCALSTACK_VOLUME_DIR:-./volume}
语法提供了一个默认值:如果在主机环境中运行 docker-compose
时,LOCALSTACK_VOLUME_DIR
环境变量未设置或设置为空字符串,则使用文本 ./volume
。
Compose 支持有限数量的环境变量扩展语法:${VARIABLE:-default}
提供了一个默认值,${VARIABLE:?error}
如果值为空或未设置,则打印错误。这两种语法都可以在没有冒号 :
的情况下使用,此时接受一个已设置但为空的值。这是标准 Bourne shell 参数扩展语法的子集,其余部分不受支持。
您最初的问题包含一个 PNG 文件,看起来包含了这个更完整的 Compose 片段:
volumes:
- ${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack
因此,如果在主机上设置了 $LOCALSTACK_VOLUME_DIR
,则将该目录挂载到 /var/lib/localstack
;如果未设置任何内容,则使用 ./volume
(相对于当前目录,如有必要则创建)。
这个特定的目录名称与您引用的文档不匹配,但行为(将目录挂载到 /var/lib/localstack
)是正确的。Compose 语法没有指定类似文档中所示的特定于操作系统的默认值。
英文:
The ${LOCALSTACK_VOLUME_DIR:-./volume}
syntax provides a default: if the LOCALSTACK_VOLUME_DIR
environment variable is either not set or set to an empty string in the host environment when docker-compose
runs, then the text ./volume
is used instead.
Compose supports a limited number of environment variable expansion syntaxes: ${VARIABLE:-default}
provides a default value, and ${VARIABLE:?error}
prints an error if a value is empty or isn't set. Both syntaxes can be used without the colon :
, in which case a set-but-empty value is accepted. This is a subset of the standard Bourne shell parameter expansion syntaxes; the remainder are not supported.
Your original question had a PNG file that looked like it contained this more complete Compose fragment:
volumes:
- ${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack
So if $LOCALSTACK_VOLUME_DIR
is set on the host, that directory is mounted into /var/lib/localstack
; if nothing is set, then ./volume
is (relative to the current directory, created if necessary).
This specific directory name doesn't match the documentation you quote, but the behavior (that the directory is mounted on to /var/lib/localstack
) is correct. There isn't Compose syntax to specify an OS-specific default like what that documentation would imply.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论