mysql - 如何构建用于连接数据库(8080)和超集的 SQLAlchemy URI?
问题描述
使用命令拉取 MySQL 镜像
docker pull mysql
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
然后在我的根目录中为mysql创建了一个stack.yml文件
stack.yml :
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
最后把它组合起来。
docker-compose -f stack.yml up (after making the stack.yml file)
在它停止运行后,我访问了 localhost:8080 页面并加载了 mysql 数据库登录页面。
超集设置
git clone https://github.com/apache/incubator-superset.git
cd incubator-superset
docker-compose up
访问 localhost:8088 页面上的超集。
如何构建用于连接数据库和超集的 SQLAlchemy URI?
解决方案
您可以单独访问这两个应用程序,因为它具有不同的桥接网络。但是当涉及到彼此连接时,您必须通过相同的网络连接两个应用程序。Superset 已经在incubator-superset_default上运行,而 MySQL 在默认桥接网络上运行。
这里测试了stack.yaml
version: '3.7'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
container_name: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: sample
networks:
- proxynet
networks:
proxynet:
name: incubator-superset_default
注意:作为用户自定义网络所以使用可以使用服务容器名称或容器IP地址如下
mysql://root:sample@mysql/mysql mysql://root:sample@172.19.0.5/mysql