I have a rails app that I’m trying to containerize locally using docker-compose
. I am consistently getting a “database does not exist” error from docker-compose
but the database name is a name I’m no longer using. Here is the error message:
db-1 | 2024-08-02 20:41:07.758 UTC [187] FATAL: database “climate_control” does not exist
The project is named “Climate Control” and the databases are named following the convention “climate_control_[environment name]” – this is my database.yml file:
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
Nothing named just “climate_control” in there. I do have a user named “climate_control”, but I can’t see how that would affect the name of the database the project is trying to use.
I am specifying some environment variables (POSTGRES_DB
, POSTGRES_USER
, and POSTGRES_PASSWORD
) in docker-compose.yml, but POSTGRES_DB
is set correctly. Here is the entire file:
# 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
I have tried rebuilding the docker images:
docker-compose down
docker-compose up --build
I have cleared the Rails cache:
docker-compose exec web rails tmp:cache:clear
I have removed everything from the tmp/
directory:
rm -rf tmp/*
I have searched the codebase for all instances of the string “climate_control” and found only the user names. The entire project is viewable at https://github.com/fredwillmore/climate-control – there’s nothing proprietary about it, I’m just trying to create a resume project.
I’m out of ideas, I would welcome any recommendations!