4 Solutions collect form web for “How would I pass environment into docker using bash?”

Bash arrays are designed to solve exactly this sort of problem

First step is to declare the array:

docker_env=(-e "a=hello world" "b=world")

Which lets you programmatically populate more environment variables, for example:

docker_env+=("c=foo bar")

Finally run it:

docker run -i -t -rm "${docker_env[@]}" ubuntu /bin/bash

How about instead:

a='hello world'
b='some more'
docker run -i -t -rm -e a -e b ...

Does this do what you need in an eaiser way?

eval docker run -i -t -rm "$ENV_VARS" ubuntu /bin/bash

I solved problem of the space containing variables passed to docker environment using option –env-file. In the env file the line separated variable definitions are expected. Following example illustrates the pattern.