【发布时间】:2021-05-02 19:25:46
【问题描述】:
我有一个带有 Dockerized PostgreSQL 数据库的 Rails 应用程序。当我运行rails db 或rails db:migrate 时,它工作得非常好。
当我运行rails db:create 时,它的行为有所不同:
$ rails db:create
Created database 'my_app_development'
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Couldn't create 'my_app_test' database. Please check your configuration.
rails aborted!
ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/rails:5:in `<top (required)>'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:10:in `block in <top (required)>'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:7:in `tap'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:7:in `<top (required)>'
Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/rails:5:in `<top (required)>'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:10:in `block in <top (required)>'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:7:in `tap'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
我的怀疑是,由于某种原因,rails db:create 试图连接到我在127.0.0.1:5432 上的数据库(这可行),但随后又试图在localhost:5432 上再次连接到它,这将无法正常工作,因为localhost 赢了不要去我的容器,只有127.0.0.1:5432会。
同样,rails db 和 rails db:migrate 工作正常。当我尝试rails db:create 和rails db:drop 时,我得到了上面的错误。
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails postgresql docker