[英]fe_sendauth: no password supplied (PG::ConnectionBad) Docker container
I followed a tutorial to dockerize an existing rails application.我按照教程对现有的 rails 应用程序进行了 dockerize。 The app is running successfully in development env.
该应用程序在开发环境中成功运行。 But when I try to run as stating env I'm getting the error.
但是当我尝试以声明env 的方式运行时,我收到了错误消息。 I have kept same config for stating and development.
我为陈述和开发保留了相同的配置。 Here are my related files:
这是我的相关文件:
database.yml数据库.yml
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
pool: 10
timeout: 5000
database: <%= ENV['DATABASE_NAME'] %>
username: <%= ENV['DATABASE_USER_NAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: db
port: 5432
staging:
<<: *default
pool: 10
timeout: 5000
database: <%= ENV['DATABASE_NAME'] %>
username: <%= ENV['DATABASE_USER_NAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: db
port: 5432
application.yml应用程序.yml
development:
DATABASE_USER_NAME: 'developer'
DATABASE_PASSWORD: 'qmwneb10PG'
DATABASE_NAME: 'concern_box'
staging:
DATABASE_USER_NAME: 'developer'
DATABASE_PASSWORD: 'qmwneb10PG'
DATABASE_NAME: 'concern_box'
docker-compose.yml docker-compose.yml
version: '3'
services:
app:
build: .
container_name: cb_app_container
db:
container_name: cb_db_container
image: postgres:9.6
hostname: postgres
ports:
- "5432:5432"
docker-compose.stag.yml docker-compose.stag.yml
version: '3'
services:
app:
environment:
RAILS_ENV: staging
command: bundle exec rails s -p 80 -b '0.0.0.0'
ports:
- "80:80"
depends_on:
- db
db:
volumes:
- ./tmp/db:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
docker-compose.dev.yml docker-compose.dev.yml
version: '3'
services:
app:
command: bundle exec rails s -p 3000 -b '0.0.0.0'
stdin_open: true
tty: true
volumes:
- .:/concern-box
ports:
- "3001:3000"
depends_on:
- db
db:
volumes:
- ./tmp/db:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
init.sql初始化程序
CREATE USER developer WITH PASSWORD 'qmwneb10PG';
CREATE DATABASE concern_box;
GRANT ALL PRIVILEGES ON DATABASE concern_box TO developer;
I'm using following commands to spin the containers docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --force-recreate
for development env and docker-compose -f docker-compose.yml -f docker-compose.stag.yml up --force-recreate
to run as staging env.我正在使用以下命令来旋转容器
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --force-recreate
for development env 和docker-compose -f docker-compose.yml -f docker-compose.stag.yml up --force-recreate
作为暂存环境运行。
On database.yml, development
and staging
are loading from ENV[], you your container should have secrets loaded from Os environment在 database.yml 上,
development
和staging
是从 ENV[] 加载的,你的容器应该有从 Os 环境加载的秘密
Do not forget to load you secret into the host environment, or use env_file feature from docker-compose不要忘记将您的机密加载到主机环境中,或者使用 docker-compose 中的 env_file 功能
docker-compose.stag.yml docker-compose.stag.yml
version: '3'
services:
app:
environment:
RAILS_ENV: staging
DATABASE_USER_NAME: ${DATABASE_USER_NAME} # <-- Add this
DATABASE_PASSWORD: ${DATABASE_PASSWORD} # <-- Add this
DATABASE_NAME: ${DATABASE_NAME} # <-- Add this
command: bundle exec rails s -p 80 -b '0.0.0.0'
ports:
- "80:80"
depends_on:
- db
db:
expose:
- 5432 # Just to make sure app will see the port
volumes:
- ./tmp/db:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
docker-compose.dev.yml docker-compose.dev.yml
version: '3'
services:
app:
command: bundle exec rails s -p 3000 -b '0.0.0.0'
environment:
DATABASE_USER_NAME: ${DATABASE_USER_NAME} # <-- Add this
DATABASE_PASSWORD: ${DATABASE_PASSWORD} # <-- Add this
DATABASE_NAME: ${DATABASE_NAME} # <-- Add this
stdin_open: true
tty: true
volumes:
- .:/concern-box
ports:
- "3001:3000"
depends_on:
- db
db:
expose:
- 5432 # Just to make sure app will see the port
volumes:
- ./tmp/db:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
database.yml load from ENV[], not from a file application.yml
database.yml 从 ENV[] 加载,而不是从文件
application.yml
database.yml
...
staging:
<<: *default
pool: 10
timeout: 5000
database: <%= ENV['DATABASE_NAME'] %>
username: <%= ENV['DATABASE_USER_NAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: db
port: 5432
...
application.yml
staging:
DATABASE_USER_NAME: 'developer'
DATABASE_PASSWORD: 'qmwneb10PG'
DATABASE_NAME: 'concern_box'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.