How can I pass a multi-line variable to a docker container?

According to this comment, multi-line variables are supported with docker compose:

  KEY: |-

However, when I execute echo $KEY in the container, it has replaced the newline with spaces:

  • Managing remote docker machines from multiple development machines
  • Multi-host Docker compose application on Swarm
  • multiple docker clients on the same machine
  • why run exec command?
  • Can I reference the service name docker-compose.yml
  • Gitlab CI: mount Apache service Docker DocumentRoot directory into main Docker
  • line1 line2

    Am I missing something? My docker version is 1.12.1.

  • Docker image NGINX not exposing : site cannot be reached
  • Can't access Heapster's InfluxDB port 8083
  • How to avoid permission deny with uid/gid 1000 after mount volume with docker?
  • How to show the ID of the oldest running docker container?
  • Docker container IP's not communicating in kubernetes cluster
  • Cache docker images on Travis CI
  • 2 Solutions collect form web for “How can I pass a multi-line variable to a docker container?”

    The YAML syntax is correct. The shell command wasn’t:

    echo "$KEY"

    prints the string with newlines.

    Had the same problem a couple of days ago and solved it via:

    KEY: "line1\nline2"

    Hope that helps in your case as well.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.