Docker postgresql start directory in a volume

  docker, docker-compose, postgresql, synology

Trying to run a postgresql db located in a directory (easily running from Mac or Ubuntu with pg_ctl start -D pgdirectory/ )

docker network create pgnet

docker run -it --rm 
    --name pgdockerdb 
    --network pgnet 
    -p 5436:5432  #  postgres is running in 5432 locally
    -v /local/path/to/pgdb:/var/lib/postgresql/data 
    -e POSTGRES_DB=pgdb 
    -e POSTGRES_USER=pguser 
    -e POSTGRES_PASSWORD=sstrongggpass 

I receive following answer (translated from spanish to english -> I don’t know exact words that postgresql should write in english):

…first lines trying to create a new db…
initdb: error: directory «/var/lib/postgresql/data» exists but it is not empty
If you wan to create a new database cluster, erase or empty
the directory «/var/lib/postgresql/data», or exec initdb
with a different argument than «/var/lib/postgresql/data».
db exited with code 1

I tried to include a sh with pg_ctl start -D . in volume /docker-entrypoint-initdb.d/

I tried to include PUID and PGID enviroment variables in docker-compose.yml from id $user (root, user or 999 [because docker y chowning files to that user])

Worst thing is that one time worked but when y copied the up-to-date db, never worked again.

Source: Docker Questions