questions about docker –link parameter

As we know, in one host with docker daemon, containers connect to the docker0 bridge, and so containers can access each other by default.

Then what’s the use of --link option? Is it any different with the direct access by ip way?

  • How can I upgrade openshift origin if it is run as a docker container?
  • How do I run 2 environments of SkyDns/Skydock simultaneously?
  • Docker application deployment DEV vs TEST
  • Docker Tomcat7 container not always starting correctly
  • Is it possible to start multiple docker daemons on the same machine
  • What is the different between putting a separate service discovery and integrate it into the cluster machine in Docker Swarm
  • What does it actually do?

  • How to load balance services in CoreOS?
  • How can I set negative niceness of a docker process?
  • boot2docker vm forgets changes when restarted
  • How can I map a shared folder from my container on Mac?
  • install nvm in docker
  • Setting up private docker registry with a frontend
  • 3 Solutions collect form web for “questions about docker –link parameter”

    From the Docker docs:

    When you set up a link, you create a conduit between a source container and a recipient container. The recipient can then access select data about the source

    When two containers are linked, Docker will set some environment variables in the target container to enable programmatic discovery of information related to the source container.

    And some more:

    In addition to the environment variables, Docker adds a host entry for the source container to the /etc/hosts file. Here’s an entry for the web container:

    So, basically --link creates a set of environment variables and adds some entries to the /etc/hosts file in order to ease communication. But, the containers are still directly accessed via IP.

    When you create a container using --link option, Docker exposes the linked container into the new one in two ways:

    • It creates a entry in /etc/hosts with the IP of the linked container and the alias given when creating the link.
    • It exposes some information as environmental variables about the linked container. As Docker documentation shows:

    Docker will then also define a set of environment variables for each port that is exposed by the source container. The pattern followed is:

    <name>_PORT_<port>_<protocol> will contain a URL reference to the port. Where <name> is the alias name specified in the --link parameter (e.g. webdb), <port> is the port number being exposed, and <protocol> is either TCP or UDP. The format of the URL will be: <protocol>://<container_ip_address>:<port> (e.g. tcp://172.17.0.82:8080). This URL will then be split into the following 3 environment variables for convenience:
    <name>_PORT_<port>_<protocol>_ADDR will contain just the IP address from the URL (e.g. WEBDB_PORT_8080_TCP_ADDR=172.17.0.82).
    <name>_PORT_<port>_<protocol>_PORT will contain just the port number from the URL (e.g. WEBDB_PORT_8080_TCP_PORT=8080).
    <name>_PORT_<port>_<protocol>_PROTO will contain just the protocol from the URL (e.g. WEBDB_PORT_8080_TCP_PROTO=tcp).
    

    It is not differences if you access via IP, but using links let setting the container ignoring the ip that will be assigned by Docker Daemon. Check Docker documentation for further information.

    If you start the docker using --icc=false option, the container can’t communicate to each other by default. You must use --link to connect two containers.

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