使用已有数据库
创建本地数据库
数据库:nocodb
用户:nocodb
密码:xxxxxx
修改docker-compose.yml
默认网关的 IP 地址是 172.17.0.1(适用于 bridge 网络模式)
version: "2.1"
services:
nocodb:
environment:
# 更新数据库连接信息为宿主机的 MySQL
NC_DB: "mysql2://172.17.0.1:3306?u=nocodb&p=xxxxxx&d=nocodb"
image: "nocodb/nocodb:latest"
ports:
- "28080:8080"
restart: always
volumes:
- "/opt/ai-server/nocodb_data:/usr/app/data"
volumes:
nc_data: {}
启动镜像
docker compose up -d
查看日志
docker ps
docker logs nocodb-nocodb-1 (根据上一步获取的名称来查看)
找到
[Nest] 9 - 12/27/2024, 8:02:03 AM ERROR [ExceptionHandler] Error: Access denied for user 'nocodb'@'172.25.0.2' (using password: YES)
给用户授权IP访问
mysql-5.7.14
mysql -h 127.0.0.1 -P 3306 -u root -p xxxxxxxx
GRANT ALL PRIVILEGES ON nocodb.* TO 'nocodb'@'172.25.0.2';
FLUSH PRIVILEGES;
等待nocodb自动重启
访问
http://127.0.0.1:28080
使用独立的docker中新的mysql
配置 docker-compose.yml
version: "2.1"
services:
nocodb:
depends_on:
root_db:
condition: service_healthy
environment:
NC_DB: "mysql2://root_db:3306?u=noco&p=password&d=root_db"
image: "nocodb/nocodb:latest"
ports:
- "28080:8080"
restart: always
volumes:
- "nc_data:/usr/app/data"
root_db:
environment:
MYSQL_DATABASE: root_db
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: noco
healthcheck:
retries: 10
test:
- CMD
- mysqladmin
- ping
- "-h"
- localhost
timeout: 20s
image: "mysql:8.3.0"
restart: always
volumes:
- "db_data:/var/lib/mysql"
volumes:
db_data: {}
nc_data: {}
注意修改一些敏感数据
启动
docker compose up -d
访问
http://127.0.0.1:28080