title: Docker swarm tries to parse the value of ENV variable in my compose file (because it has a go template in it) and gives me an error
body: <h1>The error</h1>
  
  <p>I try to launch a logspout container and set the log format (an ENV variable) via a docker-compose file. Not too difficult, and if I launch it with <code>docker-compose up</code>, everything works fine. But when I try to launch it with  docker <code>swarm init</code> and <code>docker stack deploy -c docker-compose.yml mystack</code>, I get an error:</p>
  
  <p><em>Error response from daemon: rpc error: code = InvalidArgument desc = expanding env failed: expanding env "RAW_FORMAT={ \"container\" : \"{{ .Container.Name }}\", \"labels\": {{ toJSON .Container.Config.Labels }}, \"timestamp\": \"{{ .Time.Format \"2006-01-02T15:04:05Z07:00\" }}\", \"source\" : \"{{ .Source }}\", \"message\": {{ toJSON .Data }} }": template: expansion:1: function "toJSON" not defined</em></p>
  
  <h1>What I understand</h1>
  
  <p>I think I have the error only with swarm and not docker-compose, because the ENV variable I want to pass to logspout is:</p>
  
  <p><em>RAW_FORMAT: '{ "container" : "{{ .Container.Name }}", "labels": {{ toJSON .Container.Config.Labels }}, "timestamp": "{{ .Time.Format "2006-01-02T15:04:05Z07:00" }}", "source" : "{{ .Source }}", "message": {{ toJSON .Data }} }'</em></p>
  
  <p>This ENV variable contains a go template. But with swarm mode, you can <a href="https://docs.docker.com/engine/swarm/services/#create-services-using-templates" rel="nofollow noreferrer">create services using go-templates</a>. So it seems that swarm tries (and fails) to parse the value of the ENV variable that I just want to pass to the logspout container.</p>
  
  <h1>My question</h1>
  
  <ol>
  <li><p>Is it a way to tell swarm not to parse the go-template in my RAW_FORMAT variable?</p></li>
  <li><p>If not, is there an other way to set this variable to the correct value?</p></li>
  </ol>
  
  <h1>More...</h1>
  
  <p>If you want to reproduce this problem, here is a minimal docker-compose file:</p>
  
  <pre><code>version: "3.3"
  services:
  logspout:
    image: gliderlabs/logspout:latest
    volumes:
      - /etc/hostname:/etc/host_hostname:ro
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      RAW_FORMAT: '{ "container" : "{{ .Container.Name }}", "labels": {{ toJSON .Container.Config.Labels }}, "timestamp": "{{ .Time.Format "2006-01-02T15:04:05Z07:00" }}", "source" : "{{ .Source }}", "message": {{ toJSON .Data }} }'
  </code></pre>
  
  <p>If you are on windows, you have to execute <code>$Env:COMPOSE_CONVERT_WINDOWS_PATHS=1</code> first.</p>