You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署Commento遭遇PostgreSQL版本不兼容错误求助

问题:PostgreSQL版本不兼容导致Docker容器启动失败

错误日志如下:

db-1      |
db-1      | PostgreSQL Database directory appears to contain a database; Skipping initialization
db-1      |
db-1      | 2023-12-09 23:47:52.107 UTC [1] FATAL:  database files are incompatible with server
db-1      | 2023-12-09 23:47:52.107 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 16, which is not compatible with this version 13.13 (Debian 13.13-1.pgdg120+1).
db-1 exited with code 1

我的Docker Compose配置:

version: '3'

services:
  server:
    image: registry.gitlab.com/commento/commento:v1.4.0
    ports:
      - 8080:8080
    environment:
      COMMENTO_ORIGIN: http://127.0.0.1:8080
      COMMENTO_PORT: 8080
      COMMENTO_POSTGRES: postgres://postgres:admin@db:5433/commento?sslmode=disable
    depends_on:
      - db
  db:
    image: postgres:13
    environment:
      POSTGRES_DB: postgres 
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: admin
    volumes:
      - postgres_data_volume:/Program Files/PostgreSQL/13/data

volumes:
  postgres_data_volume:

已尝试的操作:

  • 修改版本号后重新初始化数据目录
  • 通过initdb --version确认版本正确
  • 卸载PostgreSQL 16版本
  • 检查端口号以确保使用PostgreSQL 13的对应端口

我是Docker新手,目前不知如何继续排查。我使用的工具是已停止维护的Commento,因此需要使用较旧的PostgreSQL版本。


解决方法

核心问题是Docker卷postgres_data_volume中已存储PostgreSQL 16初始化的数据文件,当前用PostgreSQL 13容器读取这些文件时,因版本不兼容导致启动失败。宿主机卸载PostgreSQL 16的操作不影响Docker容器卷内的数据。

操作步骤:

  1. 停止并删除当前容器及关联卷(会清空数据库数据,若需保留请先备份):
    docker-compose down -v
    
  2. 重新启动容器,PostgreSQL 13会自动初始化兼容的数据目录:
    docker-compose up -d
    

额外注意:Docker Compose中COMMENTO_POSTGRES连接字符串的端口是5433,但PostgreSQL容器默认内部端口为5432,若未在db服务中修改端口配置,建议将连接字符串端口改为5432,避免后续连接失败:

postgres://postgres:admin@db:5432/commento?sslmode=disable

内容的提问来源于stack exchange,提问作者Jonah Legg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 05:02:18