title: docker container can not connect to local postgres
body: <p>Can't connect to Postgres from the docker container.
  I do not want user docker-compose and create a Postgres container, already got Postgres app running. I think it is a bad idea to container postgres and better use system.</p>
  
  <p>OSX, Postgres10, Flask</p>
  
  <p>I already made</p>
  
  <p><strong>postgresql.conf</strong></p>
  
  <pre><code>listen_addresses = '*'  
  port = 5432
  </code></pre>
  
  <p><strong>pg_hba.conf</strong></p>
  
  <pre><code>host    all             all             0.0.0.0/0               trust
  </code></pre>
  
  <p><em>I Used trust for any result, but no effect.</em></p>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>FROM python:3.8-alpine
  RUN apk update \
      &amp;&amp; apk add --virtual build-deps gcc musl-dev \
      &amp;&amp; apk add python3-dev \
      &amp;&amp; apk add postgresql-dev \
      &amp;&amp; apk add jpeg-dev zlib-dev libjpeg \
      &amp;&amp; pip install --upgrade pip
  ENV PYTHONUNBUFFERED 1 \
      &amp;&amp; FLASK_APP app.py
  #EXPOSE 5000 5432
  WORKDIR /app
  ADD . /app
  RUN pip install -r requirements.txt
  CMD ["./bin/run.sh"]
  </code></pre>
  
  <p><strong>./bin/run.sh</strong></p>
  
  <pre><code>#!/bin/sh
  #python run.py
  source venv/bin/activate
  set -e
  flask db upgrade
  exec gunicorn -b --workers 4 --access-logfile --error-logfile run:app :5000
  </code></pre>
  
  <p><strong>The "docker run" command I try to use:</strong></p>
  
  <pre><code>docker run --rm -e SQLALCHEMY_DATABASE_URI=postgresql://postgres:postgres@0.0.0.0:5432/my_db --net=host -p 5000:5000 my_container:v0.1
  </code></pre>
  
  <p>the command leads to error</p>
  
  <pre><code>...
  psycopg2.OperationalError: could not connect to server: Connection refused
          Is the server running on host "0.0.0.0" and accepting
          TCP/IP connections on port 5432?
  </code></pre>
  
  <p><strong>command connect me to Postgres</strong></p>
  
  <pre><code>psql -U postgres -h 0.0.0.0
  </code></pre>