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.
OSX, Postgres10, Flask
I already made
postgresql.conf
listen_addresses = '*'
port = 5432
pg_hba.conf
host all all 0.0.0.0/0 trust
I Used trust for any result, but no effect.
Dockerfile
FROM python:3.8-alpine
RUN apk update \
&& apk add --virtual build-deps gcc musl-dev \
&& apk add python3-dev \
&& apk add postgresql-dev \
&& apk add jpeg-dev zlib-dev libjpeg \
&& pip install --upgrade pip
ENV PYTHONUNBUFFERED 1 \
&& FLASK_APP app.py
#EXPOSE 5000 5432
WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
CMD ["./bin/run.sh"]
./bin/run.sh
#!/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
The "docker run" command I try to use:
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
the command leads to error
...
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?
command connect me to Postgres
psql -U postgres -h 0.0.0.0