Reputation: 332
I have mysql and an application running on the docker. I want the application to connect to mysql localhost inside the docker.
Upvotes: 0
Views: 333
Reputation: 4150
Every container in Docker is a different host with its own IP and hostname, that's why you can't connect to your DB from your app using 127.0.0.1, they are not running on the same host.
You can see the IP assigned to a container with docker inspect <container-id>
, but more easily you can refer to a service running on a container by its host, which by default is the name of the container (db
in your case). You can also customize the hostname using hostname
as you did.
Set db
(or hybris_dev
depending on how you prefer to configure your container) as the hostname to establish the connection to your DB from your app and it should work.
Upvotes: 2