1

How do I access the environment variables of a source container from another container which is linking to it with the --link argument? The docker manual states:

Environment Variables

Docker creates several environment variables when you link containers. Docker automatically creates environment variables in the target container based on the --link parameters. It will also expose all environment variables originating from Docker from the source container. These include variables from:

  • the ENV commands in the source container's Dockerfile
  • the -e, --env and --env-file options on the docker run command when the source container is started

http://docs.docker.com/userguide/dockerlinks/

But I can't access an environment variable which I set with

ENV MY_VARIABLE = "example"

in the linking container with

#!/bin/sh
echo $MY_VARIABLE

it will contain no value.

1 Answer 1

2

Environment variables from the source container are prefixed with the alias set with the --link <source container>:<alias> in the target container:

$<alias>_ENV_<env variable>

The environment variable will be accessible as follows if <alias> is e.g. set to source:

#!/bin/sh
echo $SOURCE_ENV_MY_VARIABLE
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.