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:

  • Running on runner-…-concurrent-0 via … runner for LONG time never ends
  • How can I use git client to access gitlab docker?
  • Moving from Vagrant to Vagrant with Docker
  • start redis-server on debian/ubuntu boot
  • Error while cleaning images from docker
  • Docker Swarm in Multi VLAN/Subnet Application Stack
  • line1 line2

    Am I missing something? My docker version is 1.12.1.

  • Error when Dockerizing a sails app with docker-toolbox
  • An error occurred trying to connect - docker when not using sudo
  • Strange state of docker on Windows
  • Iscsid not starting on a centos6 docker on MacOS host
  • Docker Swarm Service-Task not running
  • Seeding sclorg/mariadb container
  • 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.