`initialize':方案postgres不接受注册表部分:postgres:@(或不好的主机名?)(URI :: InvalidURIError)与Docker [英] `initialize': the scheme postgres does not accept registry part: postgres:@ (or bad hostname?) (URI::InvalidURIError) with Docker
问题描述
rails c
时,我似乎越来越错误: /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/generic.rb:204:ininitialize:方案postgres不接受注册表部分:postgres:@ (或不好的主机名?)(URI :: InvalidURIError)
加工?
我的 database.yml
是:
production:
<< ;: * default
url:<%= ENV ['DATABASE_URL']%>
$ DATABASE_URL
被定义
有趣的是,它工作了几天,直到昨天,并且今天停止工作。
下面是Rails 4.2.1生成的和/ etc / secrets.yml一样,你永远不想存储敏感信息,
#就像你的数据库一样,
$ b $密码,在您的源代码。如果您的源代码是
#,任何人都可以看到,他们现在可以访问您的数据库。
#
#相反,当您启动
#的应用程序时,提供密码作为unix环境变量。有关如何在
#production部署中提供这些环境变量,请参阅http://guides.rubyonrails.org/configuring.html#configuring-a-database
#。
#
#对于Heroku和其他平台提供商,您可能有一个完整的连接URL
#作为环境变量。例如:
#
#DATABASE_URL =postgres:// myuser:mypass @ localhost / somedatabase
#
#您可以使用此数据库配置:
#
#production:
#url:<%= ENV ['DATABASE_URL']%>
为什么会推荐env变量是保留的?
更新:其实这还没有修复。在运行
rails runner
由cron运行时,环境变量看起来不会从database.yml
文件中拾取任务调用Sidekiq的工作(每次使用)。我不得不将url:
静态值替换为现在可以正常工作,但是由于$ code> docker ip每次都会更改从图像中运行,我喜欢rails runner
来正确地拾取环境变量。这可能与 https://github.com/rails/rails/issues/ 19256#issuecomment-102980786 ,但解决方案也无效。
重命名你的环境变量!
DATABASE_URL
由Rails保留,并由ActiveRecord本身解释。我遇到同样的问题。
而是使用这样的东西:
host:<%= ENV ['DB_HOST']%>
密码:<%= ENV ['DB_PWD']%>
I'm using Rails with Postgres DB Docker container attached. It looks like I'm getting below error when I run rails c
:
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/generic.rb:204:in `initialize': the scheme postgres does not accept registry part: postgres:@ (or bad hostname?) (URI::InvalidURIError)
Is there a reason why this isn't working?
My database.yml
is:
production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
$DATABASE_URL
is defined
Interestingly it was working for a few days until yesterday and stopped working again today.
Below is what Rails 4.2.1 generates!
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
Why on earth would they recommend env variable that is reserved!?
UPDATE: Actually this is still not fixed. It looks like environment variable is not being picked up from
database.yml
file when runningrails runner
which is run by cron task to invoke Sidekiq worker job (using Whenever). I had to puturl:
static value instead to get it working for now but given thatdocker
ip changes every time its run from the image I would preferrails runner
to pick up environment variables properly. This may be related to https://github.com/rails/rails/issues/19256#issuecomment-102980786 but the solution didn't work either.
Rename your environment variable!
DATABASE_URL
is reserved by Rails, and interpreted by ActiveRecord itself. I ran into the same issue.
Instead, use something like this:
host: <%= ENV['DB_HOST'] %>
password: <%= ENV['DB_PWD'] %>
这篇关于`initialize':方案postgres不接受注册表部分:postgres:@(或不好的主机名?)(URI :: InvalidURIError)与Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!