Andriy Kopachevskyy
Andriy Kopachevskyy

Reputation: 7686

Pass an environment variable to Docker

Here is a particular operation everyone can try:

docker run --env TEST='xxx' ubuntu:14.04 /bin/echo $TEST

That returns an empty string.

Upvotes: 3

Views: 9777

Answers (2)

ronkot
ronkot

Reputation: 6347

The reason why echoing isn't working is that the $TEST environment variable is substituted on your host side. To postpone the substitution to container side, wrap the echo command with single quotes:

docker run --env TEST='xxx' ubuntu:14.04 sh -c 'echo $TEST'

Upvotes: 11

Oleg Kuralenko
Oleg Kuralenko

Reputation: 11543

You're substituting TEST in your bash instead of your container. Try this command to make sure your variable is passed correctly:

docker run --env TEST='xxx' ubuntu:14.04 /usr/bin/env

Upvotes: 5

Related Questions