I’m trying to run latest version of PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) using docker-compose
# Use postgres/pswd user/password credentials
version: '3.1'
services:
db:
image: postgres
restart: unless-stopped
environment:
POSTGRES_PASSWORD: pswd
POSTGRES_DB: auth_db
ports:
- 5432:5432
volumes:
- ./postgres:/var/lib/postgresql/data
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Start container
docker-compose up -d
[+] Running 3/3
- Network postgres-docker_default Created 0.0s
- Container postgres-docker-adminer-1 Started 0.8s
- Container postgres-docker-db-1 Started 1.1s
on attempt to connect to database from adminer (http://localhost:8080/) I’ve got Error
Unable to connect to PostgreSQL server: could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Cannot assign requested address Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
- then I try to edit
postgresql.conf
file on my mapped volume by uncommenting lineport = 5432 # (change requires restart)
- restart container
- confirm that
postgresql.conf
in docker file system have uncommented lineport = 5432 # (change requires restart)
- confirm that
- still have same error
- logs in
postgres-docker-db-1
shows that server is running…
2023-03-23 19:03:44 2023-03-23 23:03:44.498 UTC [1] LOG: starting PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-03-23 19:03:44 2023-03-23 23:03:44.498 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-03-23 19:03:44 2023-03-23 23:03:44.498 UTC [1] LOG: listening on IPv6 address "::", port 5432
2023-03-23 19:03:44 2023-03-23 23:03:44.506 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-03-23 19:03:44 2023-03-23 23:03:44.538 UTC [29] LOG: database system was shut down at 2023-03-23 23:03:37 UTC
2023-03-23 19:03:44 2023-03-23 23:03:44.586 UTC [1] LOG: database system is ready to accept connections
2023-03-23 19:03:44
2023-03-23 19:03:44 PostgreSQL Database directory appears to contain a database; Skipping initialization
Please give me an idea how I can connect to postgres?
2
Answers
adminer container don’t have database on localhost
The problem is you’re using
localhost
, there are different types of network solutions in Docker. The default one is bridge network, you only need to usedb:5432
(the service name fromdocker-compose.yml
) instead oflocalhost:5432
.Tested for you 🙂