Pand-Aid / pandaid-api

backend for Pand-Aid pandemic response app
3 stars 3 forks source link

add Docker config to persist database #6

Closed EMCain closed 4 years ago

EMCain commented 4 years ago

Right now the database is erased on docker-compose down - change this in the docker config so it will be retained.

znmeb commented 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.

znmeb commented 4 years ago

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.

geophpherie commented 4 years ago

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.

znmeb commented 4 years ago

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.

bhgrant8 commented 4 years ago

Where are we at @znmeb ? appears there is a basic config to persist, but has folder been added to .gitignore, and tested on windows?

znmeb commented 4 years ago

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.

geophpherie commented 4 years ago

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.

znmeb commented 4 years ago

OK ... let me consolidate the code in the pull request #2 so we can test it.

znmeb commented 4 years ago

merged into master via pull request #12 - closing