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:

  • How to start service in docker container at start up
  • Docker not getting installed in ubuntu14.04
  • Unable to push image to Docker Hub registry
  • Verify container running state [closed]
  • Use Docker environment variables for credentials
  • Running magellan on pyspark-notebook docker container
  • line1 line2

    Am I missing something? My docker version is 1.12.1.

  • StopIteration() after a few minutes of workers job
  • Docker port forwarding not working
  • Docker public registry push fails: Repository does not exist
  • Vagrant docker provider: create and start vs run
  • HTTPS on Elastic Beanstalk (Docker Multi-container)
  • Docker: Can different containers use different base Images?
  • 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.