Пытаюсь подключиться к postgre, выходит ошибка:
Warning: pg_connect(): Unable to connect to PostgreSQL server: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address Is the server running on that host and accepting TCP/IP connections? in /code/index.php on line 2
Docker-compose:
version: '3'
services:
nginx-front:
image: nginx:1.17.8
volumes:
- ./code-front:/code
- ./docker/nginx-front.conf:/etc/nginx/conf.d/nginx-front.conf
networks:
net:
ipv4_address: 192.168.240.2
nginx-back:
image: nginx:1.17.8
volumes:
- ./public:/code-back
- ./code-back:/code
- ./docker/nginx-back.conf:/etc/nginx/conf.d/nginx-back.conf
networks:
net:
ipv4_address: 192.168.240.3
php-back:
image: php:8-fpm
volumes:
- ./code-back:/code
networks:
net:
ipv4_address: 192.168.240.4
build:
context: .
dockerfile: Dockerfile
postgres:
image: postgres:13.3
environment:
POSTGRES_DB: "messenger"
POSTGRES_USER: "admin"
POSTGRES_PASSWORD: "root"
volumes:
- ../2. Init Database:/docker-entrypoint-initdb.d
- ./messenger:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
net:
driver: bridge
ipam:
config:
- subnet: 192.168.240.0/24
Dockerfile:
FROM php:8-fpm
RUN apt-get update && \
apt-get install -y libpq-dev && \
docker-php-ext-install pdo pdo_pgsql pgsql
Как исправить?