Docker-compose rails postgres

我一直在按照这个教程来“dockerize”我的Rails应用程序,并且遇到了一些连接到数据库的障碍,经过一番search,没有任何解决scheme似乎工作。 我也尝试了默认的用户'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" 

这是我有:

.ENV

 LISTEN_ON=0.0.0.0:3000 DATABASE_URL=postgresql://web:mypassword@postgres:5432/web?encoding=utf8&pool=5&timeout=5000 

Dockerfile

 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 

泊坞窗,compose.yml

 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 

configuration/ database.yml的

 default: &default adapter: postgresql encoding: unicode pool: 5 development: <<: *default url: <%= ENV['DATABASE_URL'] %> 

database.yml的行从.env文件中获取存储在容器中的DATABASE_URL环境variables。

我花了一整天的时间摆弄这个。 最后为我工作的是回到Postgres的默认值。

泊坞窗,compose.yml

 postgres: image: postgres:9.4.5 ports: - "5432:5432" volumes: - postgres:/var/lib/postgresql/data 

.ENV

 DATABASE_URL=postgresql://web:@postgres:5432/web?encoding=utf8&pool=5&timeout=5000 

DATABASE_URL ,保持URL中的密码分隔符,但保留空白最终使其工作。