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# -f1strips inline comments from each line
This 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?
$sign with another$. You will get rid of theinvalid interpolationerror.ERROR: for foo No closing quotation# don't …cutthat strips inline comments