I have a mongo instance running in a container named mongo1
that has exposed port 27017.
I can connect just fine from the host.
I have another container that is running an application that wants to connect to the mongo instance.
How can I connect the 2 containers so that the hostname mongo1
is exposed to the other container and it can connect to mongo1:27017
?
What was happening was that the default docker network doesn't allow
name >> DNS
mapping.So I created a new network:
and then added the containers to that network:
now they can see each other by their name.
For existing containers (as Temporary solution)
and edite/add
/etc/hosts
inside the containerthen from inside the container map container_name with the IP address .. Example
.......
Or you can assign hostname for container during spining it up with
and/or add Example
echo "172.17.0.5 mango1" >> /etc/hosts
command in docker files for less headache