【发布时间】:2017-01-06 16:32:09
【问题描述】:
这是我的dockerfile,这是我的docker-compose file。当我运行docker-compose run web rake db:migrate 时,我得到了这个错误
rake aborted!
failed to execute:
pg_dump -s -x -O -f /usr/src/app/db/structure.sql --schema=public --schema=partitioning docker_rails_dev
Please check the output above for any errors and make sure that `pg_dump` is installed in your PATH and has proper permissions.
/usr/local/bundle/gems/activerecord-4.2.7.1/lib/active_record/tasks/postgresql_database_tasks.rb:90:in `run_cmd'
/usr/local/bundle/gems/activerecord-4.2.7.1/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'
/usr/local/bundle/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:183:in `structure_dump'
/usr/local/bundle/gems/activerecord-4.2.7.1/lib/active_record/railties/databases.rake:279:in `block (3 levels) in <top (required)>'
/usr/local/bundle/gems/activerecord-4.2.7.1/lib/active_record/railties/databases.rake:53:in `block (2 levels) in <top (required)>'
/usr/local/bundle/gems/activerecord-4.2.7.1/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:structure:dump
(See full trace by running task with --trace)
所以我进入 postgres 容器并运行 pg_dump 并得到了这个错误
pg_dump: [archiver (db)] connection to database "root" failed: 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"?
但运行 pg_dump --version 会给我 postgres 的版本号。
知道为什么会这样吗?
【问题讨论】:
-
pg_dump --version为您提供 pg_dump 的版本 :-) 如果您连接到容器,您将以 root 身份运行,而普通的pg_dump命令在这种情况下尝试以用户“root”身份连接到数据库“root” ”。您需要添加 -U 和 -d 等参数 - 签入文档。另外检查 pg_hba.conf 文件 - 它包含用户连接的“允许”。 -
有没有办法解决上述问题?
标签: postgresql ruby-on-rails-4 docker docker-compose dockerfile