在我的docker-compose.yml
中,我需要使用一个很长的command
,我想对其进行记录。这不容易做到,但是我有一个可以解决ALMOST问题的方法。
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
说:如果我将
$
转为$$
,它会说:我怎样才能使它正常工作?
最佳答案
这是一个更好的方法。 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