0

Установил RoR6 + postgres, заспускаю через docker-compose и получаю уведомление о запуске постгреса:

Attaching to webgram-sv_db_1, webgram-sv_web_1
db_1   | The files belonging to this database system will be owned by user "postgres".
db_1   | This user must also own the server process.
db_1   | 
db_1   | The database cluster will be initialized with locale "en_US.utf8".
db_1   | The default database encoding has accordingly been set to "UTF8".
db_1   | The default text search configuration will be set to "english".
db_1   | 
db_1   | Data page checksums are disabled.
db_1   | 
db_1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1   | creating subdirectories ... ok
db_1   | selecting dynamic shared memory implementation ... posix
db_1   | selecting default max_connections ... 100
db_1   | selecting default shared_buffers ... 128MB
db_1   | selecting default time zone ... Etc/UTC
db_1   | creating configuration files ... ok
db_1   | running bootstrap script ... ok
db_1   | performing post-bootstrap initialization ... ok
db_1   | syncing data to disk ... ok
db_1   | 
db_1   | 
db_1   | Success. You can now start the database server using:
db_1   | 
db_1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1   | 
db_1   | initdb: warning: enabling "trust" authentication for local connections
db_1   | You can change this by editing pg_hba.conf or using the option -A, or
db_1   | --auth-local and --auth-host, the next time you run initdb.
db_1   | waiting for server to start....2021-05-03 10:36:42.882 UTC [47] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-05-03 10:36:42.939 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-05-03 10:36:43.243 UTC [48] LOG:  database system was shut down at 2021-05-03 10:36:38 UTC
db_1   | 2021-05-03 10:36:43.344 UTC [47] LOG:  database system is ready to accept connections
db_1   |  done
db_1   | server started
db_1   | 
db_1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1   | 
db_1   | 2021-05-03 10:36:44.646 UTC [47] LOG:  received fast shutdown request
db_1   | waiting for server to shut down....2021-05-03 10:36:44.697 UTC [47] LOG:  aborting any active transactions
db_1   | 2021-05-03 10:36:44.700 UTC [47] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
db_1   | 2021-05-03 10:36:44.701 UTC [49] LOG:  shutting down
db_1   | 2021-05-03 10:36:45.122 UTC [47] LOG:  database system is shut down
db_1   |  done
db_1   | server stopped
db_1   | 
db_1   | PostgreSQL init process complete; ready for start up.
db_1   | 
db_1   | 2021-05-03 10:36:45.355 UTC [1] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-05-03 10:36:45.355 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2021-05-03 10:36:45.355 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2021-05-03 10:36:45.456 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-05-03 10:36:45.559 UTC [66] LOG:  database system was shut down at 2021-05-03 10:36:45 UTC
db_1   | 2021-05-03 10:36:45.598 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2021-05-03 10:49:59.702 UTC [1] LOG:  received fast shutdown request
db_1   | 2021-05-03 10:49:59.779 UTC [1] LOG:  aborting any active transactions
db_1   | 2021-05-03 10:49:59.784 UTC [1] LOG:  background worker "logical replication launcher" (PID 72) exited with exit code 1
db_1   | 2021-05-03 10:49:59.784 UTC [67] LOG:  shutting down
db_1   | 2021-05-03 10:50:00.024 UTC [1] LOG:  database system is shut down
db_1   | 
db_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1   | 
db_1   | 2021-05-03 10:50:11.243 UTC [1] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-05-03 10:50:11.245 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2021-05-03 10:50:11.245 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2021-05-03 10:50:11.405 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-05-03 10:50:11.587 UTC [26] LOG:  database system was shut down at 2021-05-03 10:49:59 UTC
db_1   | 2021-05-03 10:50:11.658 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2021-05-03 10:52:32.639 UTC [1] LOG:  received fast shutdown request
db_1   | 2021-05-03 10:52:32.688 UTC [1] LOG:  aborting any active transactions
db_1   | 2021-05-03 10:52:32.691 UTC [1] LOG:  background worker "logical replication launcher" (PID 32) exited with exit code 1
db_1   | 2021-05-03 10:52:32.698 UTC [27] LOG:  shutting down
db_1   | 2021-05-03 10:52:32.958 UTC [1] LOG:  database system is shut down
db_1   | 
db_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1   | 
db_1   | 2021-05-03 10:52:41.401 UTC [1] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-05-03 10:52:41.401 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2021-05-03 10:52:41.402 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2021-05-03 10:52:41.859 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-05-03 10:52:42.412 UTC [28] LOG:  database system was shut down at 2021-05-03 10:52:32 UTC
db_1   | 2021-05-03 10:52:42.778 UTC [1] LOG:  database system is ready to accept connections

Потом в другом терминале запускаю команду docker-compose run web rake db:create

Starting webgram-sv_db_1 ... done
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 'webgram_dc_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: 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/activerecord-6.1.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_handling.rb:283:in `connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:133:in `create'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:193:in `block in create_current'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:506:in `block (2 levels) in each_current_configuration'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:503:in `each'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:503:in `block in each_current_configuration'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:502:in `each'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:502:in `each_current_configuration'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:193:in `create_current'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <main>'

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 "/var/run/postgresql/.s.PGSQL.5432"?
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/connection_handling.rb:283:in `connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:133:in `create'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:193:in `block in create_current'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:506:in `block (2 levels) in each_current_configuration'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:503:in `each'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:503:in `block in each_current_configuration'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:502:in `each'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:502:in `each_current_configuration'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/tasks/database_tasks.rb:193:in `create_current'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

Контейнер запущен, все работает. Но пишет что не видит запущеных локально контейнеров. Как это исправить?

1 ответ 1

1

При указании postgres в docker-compose нужно указать версию. В моем случае сработало:

image: postgres:latest
4
  • 1
    Это странно ибо если версия не указана то он по-умолчанию должен тянуть latest
    – zalex
    3 мая 2021 в 17:08
  • @zalex я тоже так думал, но видимо нет. Это решение нашел на 3й странице гугла, и оно сработало 3 мая 2021 в 19:37
  • ну в этом случае попросту посмотрите контейнеры на предмет из какого образа они поднимались (ели вы их не удалили), а если удалили то можно посмотреть по крайней мере версии тех самых образов, какие именно тогда тянулись без явного указания latest ? Это было бы интересно.
    – zalex
    3 мая 2021 в 19:49
  • @zalex обрадовался что работает и удалил( 3 мая 2021 в 22:17

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.