How do I create a Docker container with a hostname that an other container can use?

So I’ve created a container for RabbitMq with the following command.

docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management

Which works fine, but I then created another container with the following command

  • Cannot find the enviromental parameter
  • Is it OK to docker a tuleap for production environment
  • Certificate errors after changing docker location on windows
  • xdebug only gets triggered via running script from cli and not browser
  • Docker Add/Copy subdirectory separately
  • How to mount volume into the source code of the app?
  • docker run test .
    

    This runs a container with a PHP file that tries to connect to the hostname, my-rabbit but it can’t find it the host so the PHP just closes itself right away. I did, however, find out the IP of the my-rabbit( first container ) and replace the hostname( my-rabbit ) in my PHP code with the IP and it connects with no problems.

    So how do I create a hostname for the RabbitMq that all the other container on the same network can see and use instead of an IP?

  • nginx ipv6 communication with docker containers
  • not able to access angular2 app from docker container
  • What's the difference between Google's Borg and Google's Kubernetes and Docker
  • Connect to a PostgreSQL database on a Docker container
  • How to get container id of a docker service
  • ssh issue of docker in redhat 6.5
  • One Solution collect form web for “How do I create a Docker container with a hostname that an other container can use?”

    I found out the answer after making this post. I use the –link arg with docker run.

    https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#communication-across-links

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