我正在尝试使用docker-compose运行Rails / Postgres应用,但是在不设置const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery'
})
)
的情况下创建数据库时遇到了麻烦。以下docker-compose.yml在“信任”下似乎可以正常工作:
POSTGRES_HOST_AUTH_METHOD="trust"
要使此工作不带“信任”,我了解到在初始化Postgres图像以设置默认用户密码时,必须定义环境变量version: '3'
services:
db:
image: postgres:alpine
env_file: .env
environment:
POSTGRES_HOST_AUTH_METHOD: "trust"
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build:
context: .
dockerfile: Dockerfile
command: bundle exec rails server -b '0.0.0.0' -p 3000
env_file: .env
ports:
- "3000:3000"
volumes:
- .:/app
- node_modules:/app/node_modules/
depends_on:
- db
volumes:
node_modules:
。因此,我们使用以下已经被docker-compose引用的.env文件:
POSTGRES_PASSWORD
并更改config / database.yml以使用以下默认连接配置:
POSTGRES_URL=db
POSTGRES_PASSWORD=foobar
然后我在控制台中执行以下操作:
...
default: &default
adapter: postgresql
encoding: unicode
host: <%= ENV['POSTGRES_URL'] %>
# If POSTGRES_PASSWORD is set in the environment then use the default user
# and that password to connect. If none is set, then assume that the creds
# are elsewhere (e.g. included in POSTGRES_URL on Heroku)
<% if ENV['POSTGRES_PASSWORD'].present? %>
username: postgres
password: <%= ENV['POSTGRES_PASSWORD'] %>
<% end %>
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
...
据我所知,这种配置应该是正确的,但是我显然忽略了某些东西。为什么我看到此身份验证失败?
答案 0 :(得分:0)
这里的问题是docker-compose run ...
永远不会运行Postgres泊坞镜映像使用的少数非常重要安装脚本。如果不是上面的命令,我们...
$ docker-compose build
$ docker-compose up db
... (wait for "database system is ready to accept connections")
$ docker-compose run web bundle exec rails db:setup
然后一切都按预期进行