0

I have mysql and an application running on the docker. I want the application to connect to mysql localhost inside the docker.

2
  • I tried links: - db:localhost Commented Oct 24, 2019 at 18:44
  • Just a guess, try connecting to mysql_hybris instead of 127.0.0.1. Commented Oct 24, 2019 at 19:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.