You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.6 KiB

Docker 部署指南

快速开始

方式一:一键启动全部服务(推荐)

Windows:

start-docker.bat

Linux/Mac:

chmod +x start-docker.sh
./start-docker.sh

启动后会自动:

  1. 构建 Docker 镜像
  2. 启动 PostgreSQL 数据库
  3. 启动 Redis
  4. 启动行情数据服务
  5. 自动创建数据库表

方式二:只启动数据库(本地开发)

如果你只想用 Docker 启动数据库,然后在本地运行 Python 服务:

start-db-only.bat

然后在本地启动服务:

python -m app.main

访问服务

启动成功后,可以通过以下地址访问:

服务 地址
行情数据服务 http://localhost:8080
管理后台 http://localhost:8080/admin
API 文档 (Swagger) http://localhost:8080/docs
API 文档 (ReDoc) http://localhost:8080/redoc

数据库连接

主机: localhost
端口: 5432
数据库: marketdata
用户名: postgres
密码: postgres123

连接字符串:

postgresql://postgres:postgres123@localhost:5432/marketdata

常用命令

# 查看日志
docker compose logs -f

# 停止服务
docker compose down

# 停止并删除数据卷(清空数据)
docker compose down -v

# 重启服务
docker compose restart

# 进入数据库容器
docker exec -it market_data_postgres psql -U postgres -d marketdata

数据结构

启动时会自动创建以下表:

股票相关表

  • stock_symbols - 股票标的表
  • stock_trading_calendar - 股票交易日历
  • stock_klines_1m - 股票1分钟K线
  • stock_klines_5m - 股票5分钟K线
  • stock_klines_1d - 股票日线K线

期货相关表

  • futures_symbols - 期货合约表
  • futures_trading_calendar - 期货交易日历
  • futures_klines_1m - 期货1分钟K线
  • futures_klines_1d - 期货日线K线

公共表

  • data_source_config - 数据源配置
  • data_quality_checks - 数据质量检查

故障排查

端口冲突

如果 5432 或 8080 端口被占用,修改 docker-compose.yml 中的端口映射:

ports:
  - "5433:5432"  # 使用 5433 代替 5432

数据库连接失败

  1. 检查容器是否运行:
docker ps
  1. 查看数据库日志:
docker logs market_data_postgres
  1. 检查数据库是否就绪:
docker exec -it market_data_postgres pg_isready -U postgres

数据持久化

数据默认存储在 Docker 卷中:

  • postgres_data - PostgreSQL 数据
  • redis_data - Redis 数据

即使删除容器,数据也不会丢失。要清空数据:

docker compose down -v