Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

environment:
  KEY: |-
    line1
    line2

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

line1 line2

Am I missing something? My docker version is 1.12.1.

like image 789
giraff Avatar asked Oct 10 '16 17:10

giraff


People also ask

How do I pass a variable in Docker?

When we launch our Docker container, we can pass environment variables as key-value pairs directly into the command line using the parameter –env (or its short form -e). As can be seen, the Docker container correctly interprets the variable VARIABLE1.

Is it possible to pass environment variables using Dockerfiles?

Passing Environment Variables Into a DockerfileDockerfile provides a dedicated variable type ENV to create an environment variable. We can access ENV values during the build, as well as once the container runs.

How do I pass an environment variable in Docker Run command?

With a Command Line Argument The command used to launch Docker containers, docker run , accepts ENV variables as arguments. Simply run it with the -e flag, shorthand for --env , and pass in the key=value pair: sudo docker run -e POSTGRES_USER='postgres' -e POSTGRES_PASSWORD='password' ...

Is it possible to run multiple process inside Docker container?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.


1 Answers

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

echo "$KEY"

prints the string with newlines.

like image 62
giraff Avatar answered Sep 18 '22 09:09

giraff