error:
....
django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Host is unreachable
Is the server running on host "db" (192.168.96.2) and accepting
TCP/IP connections on port 5432?
I checked every and each solution that I could found, but none of them works and I still have this error
you're not exposing the postgres port
I had: ports: - "5432:5432" but it did't worked
I just exposed ports like this: ports: - "5432:5432" still same problem
what returns on sudo service postgresql status sudo lsof -nP | grep LISTEN ? ——— have you run ? docker-compose up -d db docker-compose up -d web ——— Be aware, sometimes it's requires to set HOST as 127.0.0.1 in settings.py instead of "db": DATABASES = { 'default': { (...) 'HOST': '127.0.0.1', (...) } }
docker-compose.yml version: '3.8' services: db: image: postgres:12.0-alpine ports: - "5432" environment: - POSTGRES_DB=something - POSTGRES_USER=user - POSTGRES_PASSWORD=pass web: build: . command: python manage.py runserver 0.0.0.0:8000 volumes: - .:/code ports: - "8000:8000" depends_on: - db
sudo service postgresql status Redirecting to /bin/systemctl status postgresql.service Unit postgresql.service could not be found. ———- sudo lsof -nP | grep LISTEN docker-pr 654554 root 4u IPv6 7621032 0t0 TCP *:5432 (LISTEN) docker-pr 654554 654555 docker-pr root 4u IPv6 7621032 0t0 TCP *:5432 (LISTEN) docker-pr 654554 654556 docker-pr root 4u IPv6 7621032 0t0 TCP *:5432 (LISTEN) docker-pr 654554 654557 docker-pr root 4u IPv6 7621032 0t0 TCP *:5432 (LISTEN) docker-pr 654554 654558 docker-pr root 4u IPv6 7621032 0t0 TCP *:5432 (LISTEN) ———- docker-compose up -d db db run without any problem ———- docker-compose up -d api it runs and then stop ———- I've changed "db" to 127.0.0.1, and same error shows up again
I've changed docker compose to this, same error again
Обсуждают сегодня