Есть два контейнера RoR и Postgres я пытаюсь наладить между ними сеть чтобы они видели друг друга по имени.
docker-compose.yml
version: '3.2'
services:
postgres:
image: postgres
volumes:
- config-volume:/var/lib/postgresql/data/
rails:
build:
context: backend/
dockerfile: Dockerfile
links:
- "postgres:db"
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/backend
ports:
- "3000:3000"
depends_on:
- 'postgres'
angular:
build:
context: frontend/
dockerfile: Dockerfile
command: ng serve --host 0.0.0.0
volumes:
- .:/frontend
ports:
- "4200:4200"
volumes:
config-volume:
Dockerfile для бэкэнда ( RoR)
FROM ruby:2.5.1
RUN apt-get update && apt-get install -qq -y --no-install-recommends \
build-essential \
nodejs \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /rails_app
WORKDIR /rails_app
COPY . .
# RUN echo "ruby '2.5.0'\n source 'https://rubygems.org'\n gem 'rails', '~> 5.1.0'\n" > Gemfile
RUN bundle install
RUN rake db:migrate:reset
# RUN rails new temp_app
# RUN rm -rf temp_app
# CMD ['bundle', 'exec', 'rails', 'server']
config/database.yml
default: &default
adapter: postgresql
encoding: unicode
host: postgres
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
Когда делаю docker-compose build и docker-compose up получаю ошибку:
rake aborted!
PG::ConnectionBad: could not translate host name "postgres" to address: Name or service not known
/usr/local/bundle/gems/pg-1.0.0/lib/pg.rb:56:in `initialize'
/usr/local/bundle/gems/pg-1.0.0/lib/pg.rb:56:in `new'
/usr/local/bundle/gems/pg-1.0.0/lib/pg.rb:56:in `connect'
Из чего делаю вывод что линк не сработал.