title: Docker Postgres Ruby on Rails unable to connect
body: <p>I am following this tutorial from docker <a href="https://docs.docker.com/compose/rails/#connect-the-database" rel="nofollow noreferrer">Docker Rails</a> and I have created a folder and added this code below in my docker file.</p>
  
  <pre><code> FROM ruby:2.5
  RUN apt-get update -qq &amp;&amp; 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
  </code></pre>
  
  <p>And my docker compose file code is:</p>
  
  <pre><code> version: '3'
  services:
    db:
      image: postgres
      volumes:
        - .data:/var/lib/postgresql/data
    web:
      build: .
      command: bundle exec rails s -p 3000 -b '0.0.0.0'
      volumes:
        - .:/myapp
      ports:
        - "3000:3000"
      depends_on:
        - db
  </code></pre>
  
  <p>I am following tutorial when I am running docker compose up I can just see this error:</p>
  
  <pre><code>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"?
  </code></pre>
  
  <p>What is wrong here I don't know how to inspect and detect error how to fix this.</p>