In my docker-compose.yml
I need to use a very long command
, and I want to document it. This is not easily done, but I have a workaround that's ALMOST working.
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
So every command and switch can be commented.
The bash:
printf ' ... '
prints all the stuff as text, to be run as a commandgrep -v ^[[:space:]]*$
ignores the first empty linegrep -v ^#
ignores comment linescut -d# -f1
strips inline comments from each lineThis trick works perfectly in the shell !
However docker-compose up
says:
ERROR: Invalid interpolation format for "command" option in service "foo": "printf ' something ...
If I escape the $
as $$
it says:
ERROR: for foo No closing quotation
How can I get this to work?
Here's a better way. The command
docs don't show it, but I think it's standard YAML, so it's allowed.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With