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 Container's network interface in promiscuous mode
  • Can Dockerfiles chain from other Dockerfiles?
  • Kubernetes and ERR_CONNECTION_RESET
  • running three processes in docker and last .py file not found not found
  • Docker-compose dinamic hostname for instances
  • Node webservice in Docker with entrypoint fails but works otherwise
  • 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.

  • Binaries inside Docker container images not being started when not explicitly called
  • Docker: Build your own image issue
  • Cannot run my docker image
  • Change default instance disk size in the kubernetes-jenkins plugin
  • Assigning a docker container a static private ip to access it without port forwarding
  • docker run with ENTRYPOINT containing a variable
  • 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.