title: How to connect to postgres database with docker container
body: <p>Im trying to use pgAdmin to connect to my postgres container in my docker image.  But I cant seem to get it to connect.  Here is my docker-compose.yml:</p>
  
  <pre><code>version: '2'
  services:
    web:
      build: .
      command: bundle exec rails s -p 3000 -b '0.0.0.0'
      volumes:
        - .:/livingrecipe
      ports:
        - '3000:3000'
      env_file:
        - .env
      links:
        - postgres
        - elasticsearch
  
    postgres:
      image: postgres
  
    elasticsearch:
      image: elasticsearch
  </code></pre>
  
  <p>I have searched around and it looks like the localhost:5432 doesnt work unless inside the VM, but I cant find the VM IP.  Looking in Kitematic under the ports this is what it shows:</p>
  
  <p><a href="https://i.stack.imgur.com/jF3Gr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jF3Gr.png" alt="enter image description here"></a></p>
  
  <p>Ive tried specifying the ports in the docker-compose.yml file but then I get an annoying error that says the ports are already allocated and cant figure out for the life of me what is using those ports so not sure whats going on there.  Any help pointing me in the right direction either getting pgAdmin to work or just another way for me to access the database through gui like pgAdmin</p>