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

  • How do I set System Path in my dockerfile for a Windows Container?
  • MySQL 5.5.44 “native” 32% faster than dockerized MySQL 5.5.44
  • apt-get unable to locate package using custom sources.list in docker+dokku
  • Composer doesn't see GD extension
  • Connecting to MySql on Docker
  • Not able to see file after creating it using docker command and committing the changes
  • 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?

  • Which Amazon AMI for a Rails app in a Docker image?
  • Docker Compose: initialize / customize images from hub on the fly & run
  • Cannot connect to the Docker daemon on Windows 7
  • Travis-CI: docker image as build environment
  • Move docker-machine to another computer
  • Running Docker pull command in Dockerfile
  • 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.