title: Docker - host.docker.internal" (192.168.65.2) refused to connect
body: <p>I am trying to connect my PostgreSql database within Symfony and Docker and getting an error:</p>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>services:
  db:
      image: postgres:${POSTGRES_VERSION:-12}-alpine
      environment:
          POSTGRES_DB: ${POSTGRES_DB:-my_db}
          POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-root}
          POSTGRES_USER: ${POSTGRES_USER:-root}
      volumes:
          - $PWD/postgres-data:/var/lib/postgresql/data:rw
      profiles:
          - db-in-docker
      ports:
          - &quot;5432:5432&quot;
      networks:
          - symfony
  </code></pre>
  <p>And <strong>.env.dev.local</strong></p>
  <pre><code>DATABASE_URL=&quot;postgresql://root:root@host.docker.internal:5432/my_db?serverVersion=12&amp;charset=utf8&quot;
  </code></pre>
  <blockquote>
  <p>SQLSTATE[08006] [7] could not connect to server: Connection refused</p>
  <pre><code>    Is the server running on host &quot;host.docker.internal&quot; (192.168.65.2) and accepting  
      TCP/IP connections on port 5432?
  </code></pre>
  </blockquote>
  <p>I evan edited my /etc/hosts file to connect this host to <code>127.0.0.1</code></p>
  <p>As this is Postgres database that is running on my Docker host, I am using the host.docker.internal, which maps to the host IP on Mac or WindowsUsing 127.0.0.1 or localhost will cause the code to try to connect to the same container running the code, which does not have a database running.</p>
  <p>How to solve this?</p>