【发布时间】:2020-05-11 03:07:35
【问题描述】:
未添加依赖主机名,这是我的 Web 应用程序连接到我的其他服务 (postgres) 所必需的
这是我/etc/hosts的一个例子
root@bdd6f863aced:/myapp# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.21.0.3 bdd6f863aced
最后一个条目是当前容器,而不是 postgres 容器
重复步骤:
git clone repo git@github.com:tushartuteja/rails-docker-compose-example.git
cd rails-docker-compose-example
docker-compose up --build
docker ps # get the id for the web container
docker exec -it {host-container id} /bin/bash
rake db:create
cat /etc/hosts
当您尝试创建时,您会收到以下错误消息:
PG::ConnectionBad: could not translate host name "db" to address: Name or service not known
/usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:in `initialize'
/usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:in `new'
/usr/local/bundle/gems/pg-1.1.3/lib/pg.rb:56:in `connect'
docer-compose
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build: .
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
links:
- db
【问题讨论】:
标签: ruby-on-rails docker-compose