Connect to remote MySQL db from docker container

不羁岁月 提交于 2019-11-30 08:31:20
Brendenw

I solved this by using the docker host address instead of '127.0.0.1' for queries from within the container:

echo "show databases" | mysql -u DB_USER -pDB_USER_PWD -h 10.0.2.2 --port=3306

Because Docker host ip can vary, this post describes steps to get the right address:

How to get the IP address of the docker host from inside a docker container

The Docker works like a virtual machine. It has a local storage and a local environment. When you connect to 127.0.0.1 from the Docker it tries to connect to this Docker (not to local machine where the Docker was runned) because the localhost for the Docker is the Docker.

Please, read the following answer:

From inside of a Docker container, how do I connect to the localhost of the machine?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!