【发布时间】:2017-12-07 16:43:46
【问题描述】:
我从official docker-compose website 创建了 Dockerfile 到 ruby。我使用 docker compose 将其与 Postgres 集成。当 docker-compose up 时,PostgreSQL 启动但我无法连接到它。主要问题出在 ruby 数据库配置中,因为我无法更改为监听另一台主机并设置默认用户。我不知道如何在不更改 ruby 数据库配置的情况下连接这两个容器。
Dockerfile
FROM ruby:2.3.4
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
Docker 编写
version: '3'
services:
db:
image: postgres:9.6
ports:
- "5432:5432"
web:
build: .
ports:
- "4000:4000"
depends_on:
- db
Ruby 数据库.yml
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: project_development
如果我在 web conatiner "bundle exec rake db:create 中运行,我得到错误:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我不知道将连接在一起的环境集。
【问题讨论】:
标签: ruby-on-rails ruby postgresql docker