在我的 docker-compose.yml
中,我需要使用一个很长的 command
,我想记录它。这并不容易完成,但我有一个几乎可行的解决方法。
foo: # valid comment
image: foo:latest # valid comment
command: >
printf '
something # explanation for this command
--arg # explanation for this switch
--a # explanation
--b hello
-c # this does...
--d spam # don't use this when...
#some notes
--e ham # hmmm
--eggs # explanation
' |grep -v ^[[:space:]]*$ |grep -v ^# |cut -d# -f1 # valid comment
restart: always # valid comment
所以每个命令和开关都可以注释。
庆典:
printf ' ... '
将所有内容打印为文本,作为命令运行grep -v ^[[:space:]]*$
忽略第一个空行grep -v ^#
忽略注释行cut -d# -f1
从每一行中去除行内注释
这个技巧在 shell 中非常有效!
但是 docker-compose up
说:
ERROR: Invalid interpolation format for "command" option in service "foo": "printf ' something ...
如果我将 $
转义为 $$
它说:
ERROR: for foo No closing quotation
我怎样才能让它工作?
最佳答案
这是一个更好的方法。 command
文档没有显示它,但我认为它是标准的 YAML,所以它是允许的。
foo: # valid comment
image: foo:latest # valid comment
command:
- something # explanation for this command
- --arg # explanation for this switch
- --a # explanation
- --b hello
- -c # this does...
- --d spam # don't use this when...
#some notes
- --e ham # hmmm
- --eggs # explanation
restart: always # valid comment
关于linux - 在 docker-compose 命令中使用内联注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58116906/