title: docker-compose: access from docker container to localhost
body: <p>I have a service that runs inside a docker container. This service need to accesses the database that is run in another cluster (I use <code>kubectl port-forward</code> and after it I access database in <code>localhost:5432</code>) </p>
  
  <p>Here is my <code>docker-compose</code> file</p>
  
  <pre><code>version: '3'
  
  services:
    api:
      build: .
      ports:
        - "8000:8000"
        - "5432:5432"
      environment:
        - APP_PORT=8000 
        - DB_SERVER=localhost
        - DB_PORT=5432
        - DB_USER=postgres
        - DB_PASSWORD=mypassword 
  </code></pre>
  
  <p>It seems that redirection of port <code>5432</code> does not work as expected because connection to database fails inside the container. Could you help me to understand what's going wrong? </p>