Docker container link not setting environment variables

In two terminal sessions I have the following docker containers running:

docker run -i --name docker1 centos:centos6 /bin/bash

  • Docker command not available on Windows 7
  • API server failed to start up
  • Adjust OOM killer for subprocess in Docker container
  • Referencing the first argument passed to the docker entrypoint?
  • Does docker stack deploy work with local images
  • How to customize the docker run command on Elastic Beanstalk?
  • docker run -i --name docker2 centos:centos6 /bin/bash

    docker ps yields:

    8c67bb6975f7 centos:centos6 /bin/bash 7 minutes ago docker1

    8c67bb6975f7 centos:centos6 /bin/bash 7 minutes ago docker2

    (Any better way to just run an empty docker container for testing purposes btw?)

    When I run docker run -i --name link --link docker1:docker1 --link docker2:docker2 centos:centos6 /bin/bash and invoke env I get the following result:


    So as you can see I only get the NAME of the containers, and not the port and IP which is what I really want. I feel like there’s something I’ve misunderstood, but I can’t tell what it is by looking at the docs.

  • Running Wildfly Swarm with KeyCloak on docker image
  • How to use redirects in Docker
  • Docker: Unable to view running container despite successful demo example
  • How to use docker android images on
  • Why is my dockerfile not copying directories
  • Bluemix: service bound to container does not appear in VCAP_SERVICES
  • One Solution collect form web for “Docker container link not setting environment variables”

    Luckily a good friend of mine (@tobiasgwaaler) has a better grasp of Docker than I do, and he graciously gave me the answer.

    In order for a docker container to share its port and ip it needs to EXPOSE the port number. Thus, by simply adding this to my Dockerfile:

    EXPOSE <port-number>

    And huzzah, the port and IP are now available in the env

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.