Connect to remote MySQL db from docker container

后端 未结 2 1934
暖寄归人
暖寄归人 2020-12-30 02:37

I\'m working to containerize a Django 1.5.x application that connects to a MySQL DB on a separate server via ODBC:

[mysql_default]
database = DB_NAME
driver          


        
2条回答
  •  别那么骄傲
    2020-12-30 03:15

    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

提交回复
热议问题