У меня есть Rails 5, docker-compose
проект (ссылка на Github) , который отлично работает с несколькими контейнерами.
Я могу создать базу данных с помощью docker-compose exec app rails db:create
и запустить проектon localhost:3000
Проблема заключается в том, что всегда возникают ошибки: could not connect to server: No such file or directory
после успешного завершения команды.
Это проблема, когда я хочу использовать db:setup
, который выполняет 3 другихкоманды.Он завершает первую команду, а затем выдает ошибку, сообщая, что соединение потеряно, и не может выполнить оставшиеся 2 команды.
Что-то закрывает соединение между командами?Как я могу отладить это дальше?
Rails 5.2.1, pg 1.1.3 Gemfile
RAILS_ENV
определен в файле .env
.В данном случае это:
root@3ec00f6534aa:/app# printenv|grep RAILS
RAILS_ENV=development
Здесь выводится ошибка из контейнера приложения после выполнения docker-compose exec app bash
.Обратите внимание на вторую строку, в которой говорится, что БД была создана:
root@b281e881b96a:/app# rake db:setup
Created database 'sc_dev'
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>10, "database"=>"smartcitizen_testing"}
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:in `initialize'
/usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:in `new'
/usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:in `connect'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:684:in `connect'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:215:in `initialize'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:40:in `new'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:40:in `postgresql_connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:809:in `new_connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:832:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:793:in `acquire_connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:521:in `checkout'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:380:in `connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1008:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:119:in `create'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:313:in `each'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
/usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <main>'
/usr/local/bundle/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create
(See full trace by running task with --trace)