I have been working on making a postgres docker image that uses trust authentication by default for local development. Im not completely new to docker but by no means am an expert.
I found Installing PostgreSQL within a docker container for allowing local unix socket connections and How to persist data in a dockerized postgres database using volumes which explains how to persist data in a volume, but I can't put the 2 together.
WHen I run $ docker run -p 5432:5432 -v pgdata:/var/run/postgresql pgtrusted
I expect the named volume to persist and be accessible locally, but opening a new terminal and running psql
results in the error message documented in the first question
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
The error goes away when I designate the volume via
$ docker run -p 5432:5432 -v /var/run/postgresql:/var/run/postgresql pgtrusted
Which (as I understand it) anonomizes the volume. This creates the problem of not persisting any data (I created a user and a table, then stopped and restarted the container and the data was gone)
Any thoughts?