For some circumstances we cannot use mysql inside docker by sharing volume and we need to use mysql outside docker under the same machine, the big question here is: once you use mysql as daemon on MAC OS and we need have access from docker: which is localhost? localhost inside docker or localhost on my own machine? I haven't found any documentation taking about this so far. I hope this help and forget about bridge connections, sharing volumes, link, or another crazy stuff. Enjoy!
- Temporally create an mysql root account that allow external connection (a root account with a password).
- Verify the range of mysql IP used by the container services (see the example Image1) - try to make a connection from the container.
- Modify your docker-compose.yml by including
docker.for.mac.localhost
as your mysql domain (this is the only way to connect something from the container to your localhost machine on MAC OS). - Delete your mysql root account or modifying this by allowing only the docker connections (Maybe there is a better solution for this.)
update user set host='172.18.0.%' where host='%' and User='root'
or even:
update user set host='172.18.%.%' where host='%' and User='root'
- I believe the same procedure is applicable to postgres.
- Go to the top of this page and click on the Star button or write a comment on the bottom of the page.
host.docker.internal