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

使用docker-compose容器化Rails应用时数据库名称错误求助

容器化Rails应用时出现“数据库不存在”错误(目标数据库名已废弃)

错误信息

db-1 | 2024-08-02 20:41:07.758 UTC [187] FATAL: database "climate_control" does not exist

项目与配置说明

项目名为“Climate Control”,数据库命名遵循climate_control_[环境名]的约定,但错误中提及的climate_control是已不再使用的数据库名。

database.yml 配置内容

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  host: db
  database: climate_control_development
  username: <%= ENV['POSTGRES_USER'] %>
  password: <%= ENV['POSTGRES_PASSWORD'] %>

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: climate_control_test
  username: climate_control
  password: temp

production:
  database: climate_control_prod
  username: climate_control
  password: temp

配置中仅存在带环境后缀的数据库名,无单独的climate_control数据库,仅存在同名数据库用户。

docker-compose.yml 配置内容

# version: '3' # obsolete
services:
  web:
    build: .
    command: bundle exec puma -C config/puma.rb
    volumes:
      - .:/app
    ports:
      - "3000:3000"
      - "3001:3001" # for debugging
    depends_on:
      - db
    environment:
      RAILS_ENV: development
  db:
    image: postgres:14
    volumes:
      - /opt/homebrew/var/postgresql@16:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: climate_control_development
      POSTGRES_USER: climate_control
      POSTGRES_PASSWORD: temp
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U climate_control"]
      interval: 10s
      timeout: 5s
      retries: 5

已在db服务中正确设置POSTGRES_DB为climate_control_development。

已尝试的排查操作

  • 重建Docker镜像:
    docker-compose down
    docker-compose up --build
    
  • 清理Rails缓存:
    docker-compose exec web rails tmp:cache:clear
    
  • 删除tmp目录下所有内容:
    rm -rf tmp/*
    
  • 全代码库搜索climate_control字符串,仅找到用户名相关内容。

求助

目前已无排查思路,恳请提供解决建议!

内容的提问来源于stack exchange,提问作者Fred Willmore

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 03:12:40