I am new to docker rails and am attempting to implement an existing rails project in docker containers following the instructions here: https://hackernoon.com/dockerizing-an-existing-rails-postgresql-app-with-docker-compose-a30a7e1b3f40
docker-compose.yml
version: '3'
services:
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
Database.yml
default: &default
adapter: postgresql
encoding: unicode
host: db
username: postgres
pool: 5
development:
<<: *default
database: myapp_development
Dockerfile
FROM ruby:2.5.3
RUN apt-get update && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
All the containers are created and spin up just fine. I can see this from the console output after running docker-compose up. I can even connect to the rails server. However, the rails server cannot connect to the postgres server:
Is there something I am missing in my docker configuration or do I need to make a change in my rails configuration for docker?

ports 5432:5432under db indocker-composedocker-compose logs dbshow? It might be that your DB container doesn't even start in the first place because you populate the/var/lib/postgresql/datafolder, which can lead to problems.