[英]Docker-compose rails postgres
我一直在遵循本教程來“ dockerize”我的rails應用程序,並且經過一番搜索后遇到了連接數據庫的障礙,似乎沒有解決方案。 我還嘗試了默認用戶“ postgres”,沒有密碼,但是仍然沒有運氣。 我的錯誤表明我的密碼不正確,但我嘗試執行的所有操作均未更改錯誤:
web_1 | I, [2017-06-02T00:58:29.217947 #7] INFO -- : listening on addr=0.0.0.0:3000 fd=13
postgres_1 | FATAL: password authentication failed for user "web"
postgres_1 | DETAIL: Connection matched pg_hba.conf line 95: "host all all 0.0.0.0/0 md5"
web_1 | E, [2017-06-02T00:58:29.230868 #7] ERROR -- : FATAL: password authentication failed for user "web"
這是我所擁有的:
LISTEN_ON=0.0.0.0:3000
DATABASE_URL=postgresql://web:mypassword@postgres:5432/web?encoding=utf8&pool=5&timeout=5000
FROM ruby:2.3.4
RUN apt-get update && apt-get install -qq -y build-essential nodejs libpq-dev postgresql-client-9.4 --fix-missing --no-install-recommends
ENV INSTALL_PATH /web
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install
COPY . .
# precompile assets using dummy data
RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname SECRET_TOKEN=pickasecuretoken assets:precompile
VOLUME ["$INSTALL_PATH/public"]
VOLUME /postgres
CMD RAILS_ENV=development bundle exec unicorn -c config/unicorn.rb
postgres:
image: postgres:9.4.5
environment:
POSTGRES_USER: web
POSTGRES_PASSWORD: mypassword
ports:
- "5432:5432"
volumes:
- postgres:/var/lib/postgresql/data
web:
build: .
links:
- postgres
volumes:
- .:/web
ports:
- "3000:3000"
env_file:
- .env
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
database.yml
的行從.env文件中獲取存儲在容器中的DATABASE_URL
環境變量。
我花了一天的大部分時間來擺弄這個。 最終對我有用的是回到Postgres默認值。
postgres:
image: postgres:9.4.5
ports:
- "5432:5432"
volumes:
- postgres:/var/lib/postgresql/data
DATABASE_URL=postgresql://web:@postgres:5432/web?encoding=utf8&pool=5&timeout=5000
在DATABASE_URL
,將密碼分隔符保留在url中,但最后將密碼保留為空白即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.