Closed EMCain closed 4 years ago
I'll take this one, but I'll need some help testing - mounting host volumes is host-configuration dependent and I can only test on Linux and Docker Desktop for Windows.
It turns our there's a host-independent way to do this. See https://hub.docker.com/_/postgres, "Where to Store Data", first bullet point. So that's what I'm doing for now in branch znmeb-issue-6-persist-database
. I've tested it on Linux and it works, but I need to write a more formal test script.
Can I be of assistance in testing? I've spent most of my day trying to figure out docker continuity on Windows / Mac for work and spent some time on volumes.
We may not be doing it this way - there's already a pull request that fixes it https://github.com/Pand-Aid/pandaid-api/pull/2. As soon as that's merged I'm going to test it on Windows Docker Desktop.
Where are we at @znmeb ? appears there is a basic config to persist, but has folder been added to .gitignore, and tested on windows?
There are two ways to do this - see Where to Store Data on https://hub.docker.com/_/postgres. I chose the first (use a volume managed by Docker that is host-independent) and pull request #2 uses the second (a host directory, specifically the GitHub repository). There are problems with using the GitHub repo; on Linux, it creates a folder with root permissions. And if you modify it on any host you break the database. I think we should switch to the Docker-managed volume.
I agree we should move to the first implementation and let Docker handle the volume internally. As is now, I get this error on windows with the docker-compose.yml
file:
volumes:
- ./postgres-data:/var/lib/postgresql/data
postgres_1 | running bootstrap script ... 2020-03-30 10:44:47.832 UTC [81] FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
postgres_1 | 2020-03-30 10:44:47.832 UTC [81] HINT: The server must be started by the user that owns the data directory.
postgres_1 | child process exited with exit code 1
postgres_1 | initdb: removing contents of data directory "/var/lib/postgresql/data"
changing to:
volumes:
- /var/lib/postgresql/data
keeps the postgres container working.
OK ... let me consolidate the code in the pull request #2 so we can test it.
merged into master
via pull request #12 - closing
Right now the database is erased on
docker-compose down
- change this in the docker config so it will be retained.