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
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?
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.