【发布时间】:2020-07-11 17:06:07
【问题描述】:
我很抱歉再打开一个“无法连接到我的数据库”问题,但搜索了几个小时后我还是没有得到它。
我希望(非 dockerized)invoicePlane 应用程序使用 dockerized 数据库。
所以我正在使用以下 docker-compose.yml
version: '2'
services:
db:
image: mariadb:latest
#also tried mysql:latest
restart: always
environment:
MYSQL_DATABASE: 'invoiceplane_db'
MYSQL_USER: 'invoiceplane'
MYSQL_PASSWORD: 'pass1'
MYSQL_ROOT_PASSWORD: 'pass0'
expose:
- '3306'
volumes:
myserver/path:/var/lib/mysql
volumes:
invoiceplane-db:
以sudo docker-compose -f docker-compose.yml up开头
从容器内部,一切正常。我可以连接,例如通过mysql -uroot -ppass0,查看
+--------------+-----------+
| User | Host |
+--------------+-----------+
| invoiceplane | % |
| root | % |
| root | localhost |
+--------------+-----------+
3 rows in set (0.004 sec)
现在我想从主机访问数据库,尝试
mysql invoiceplane_db_1:3306 -uroot -ppass0
invoiceplane_db_1 是容器的名称。
但我总是得到:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
通过我的网络搜索,我得到的印象是这可能与容器的/etc/mysql/my.cnf 中的bind-address 有关,例如here。但我没能做对。最初,该参数被注释掉。我将其设置为bind-address = 127.0.0.1 并重新启动了容器。它没有帮助。
我在这里遗漏了什么吗?
【问题讨论】:
-
你应该将你暴露的容器端口映射到一个主机端口
标签: mysql docker docker-compose mariadb