[英]Access mariadb docker-compose container from host-machine
I'm trying to access a mariadb-container from a python script on my host-machine (MacOS).我正在尝试从我的主机(MacOS)上的 python 脚本访问 mariadb 容器。 I tried all network_modes (host, bridge, default), but nothing works.
我尝试了所有网络模式(主机、桥接、默认),但没有任何效果。 I was able to connect to the container through phpmyadmin, but only if both containers are in the same docker-compose-network.
我能够通过 phpmyadmin 连接到容器,但前提是两个容器都在同一个 docker-compose-network 中。
Here is my docker-compose.yml
with the attempt on network_mode host:这是我在 network_mode 主机上尝试的
docker-compose.yml
:
version: '3.9'
services:
mariadb:
image: mariadb:10.9.1-rc
container_name: mariadb
network_mode: bridge
ports:
- 3306:3306
volumes:
- ...
environment:
- MYSQL_ROOT_PASSWORD=mysqlroot
- MYSQL_PASSWORD=mysqlpw
- MYSQL_USER=test
- MYSQL_DATABASE=test1
- TZ=Europe/Berlin
phpmyadmin:
image: phpmyadmin:5.2.0
network_mode: bridge
container_name: pma
# links:
# - mariadb
environment:
- PMA_HOST=mariadb
- PMA_PORT=3306
- TZ=Europe/Berlin
ports:
- 8081:80
Any tips on how I get access to the container through the python mariadb package?关于如何通过 python mariadb package 访问容器的任何提示?
Thanks!谢谢!
Every thing seems okay, just check the params when trying to connect to the db:一切似乎都很好,只需在尝试连接到数据库时检查参数:
example: db = MySQLdb.connect("0.0.0.0","test","mysqlpw","test1")
例如:
db = MySQLdb.connect("0.0.0.0","test","mysqlpw","test1")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.