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?

  • What is the appropriate policy of backuping code repository for gitlab docker image?
  • Persist Changes for boot2docker guest additions
  • How to get minio-server version in docker?
  • Windows base image for docker
  • multiple docker compose container - single ip
  • Docker Container compared with Unikernel
  • What does it actually do?

  • Logstash in Docker - config file not found when mounted though a volume
  • How to mount volumes to global volume in Docker Swarm and bundle
  • Dockerizing Delayed Job
  • Docker shows inconsistent behaviour when creating container from image
  • Exposing a port other than 3000 with Express and Docker
  • How to add a file to an image in Dockerfile without using the ADD or COPY directive
  • 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:// 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=
    <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.