I am runnig postgressql in a docker container.
I have succesfully run the following using docker run:
docker run -it --rm --name postgres-master
--net postgres
-e POSTGRES_USER=postgres
-e POSTGRES_PASSWORD=Password1234!
-e POSTGRES_DB=postgres
-e PGDATA="/data"
-v ./pgdata:/data
-v ./config:/config
-v ./archive:/mnt/server/archive
-p 5000:5432
postgres:15.0 -c 'config_file=/config/postgresql.conf'
And then if I run I get the postgres prompt:
postgres -d postgres -U postgres
I then moved it to docker-compose.yaml and I get the following:
version: 3.1
services:
postgres: container_name: postgres-master
environment:
- POSTGRES_USER="postgres"
- POSTGRES_PASSWORD="Password1234!"
- POSTGRES_DB="postgres"
- PGDATA="/data"
volumes:
- ./pgdata:/data
- ./config:/config
- ./archive:/mnt/server/archive
ports:
- 5000:5432
image: postgres:15.0
command: -c 'config_file=/config/postgresql.conf'
networks:
- local
networks: local:
name: local
There are 3 dirs created. config
, data
& archive
Within the config we have page_hba.conf, postgresql.conf and pg_ident.conf.
The postgresql.conf:
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
data_directory = '/data'
hba_file = '/config/pg_hba.conf'
ident_file = '/config/pg_ident.conf'
port = 5432
listen_addresses = '*'
max_connections = 100
shared_buffers = 128MB
dynamic_shared_memory_type = posix
max_wal_size = 1GB
min_wal_size = 80MB
log_timezone = 'Etc/UTC'
datestyle = 'iso, mdy'
timezone = 'Etc/UTC'
#locale settings
lc_messages = 'en_US.utf8' # locale for system error message
lc_monetary = 'en_US.utf8' # locale for monetary formatting
lc_numeric = 'en_US.utf8' # locale for number formatting
lc_time = 'en_US.utf8' # locale for time formatting
default_text_search_config = 'pg_catalog.english'
#replication
wal_level = replica
archive_mode = on
archive_command = 'test ! -f /mnt/server/archive/%f && cp %p /mnt/server/archive/%f'
max_wal_senders = 3
The problem is with getting the psql prompt. If I try and run the following within the container:
psql -d postgres -U postgres
I get an error:
psql: error: connection to server socket /var/run/postgresql/.s.PSQL.5432" failed: Fatal"
Ive tried many things such as change the command/username, different ports. e.tc.
Do you know where I am going wrong?