Docker Community Forums

Share and learn in the Docker community.

How to pass json string as argument to compose "command"

swarm

(Arul Selvan) #1

In compose file v3.x, how to pass an argument (i.e. a json string as shown below) via “command” syntax?

Is it even possible?

 version: "3.4"
 services:
  mcrouter:
    image: mcrouter/mcrouter
    command: mcrouter -p 5000 --config-str='{ "pools": { "A": { "servers": [ "ip1:5001", "ip2:5002" ] } }, "route": "PoolRoute|A" }'

The above does not work of course giving the error below

yaml: line 38: mapping values are not allowed in this context


(Arul Selvan) #2

Found a solution. The following works.

 version: "3.4"
 services:
  mcrouter:
    image: mcrouter/mcrouter
    command: >- 
      mcrouter -p 5000 --config-str='{ "pools": { "A": { "servers": [ "ip1:5001", "ip2:5002" ] } }, "route": "PoolRoute|A" }'

Ref: YAML block folded style