Add volume persistence for PostgreSQL and bakerydemo media in docker-compose #579
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Docker Compose Volume Persistence
Summary
This PR adds persistent volumes to docker-compose.yml to prevent data loss when running
docker-compose down. Previously, both the PostgreSQL database and media files were lost on container shutdown, requiring users to runload_initial_dataon every restart.Changes
PostgreSQL Data Persistence
Added a named volume
postgres_datato persist the database across container restarts:/var/lib/postgresql/data/inside the containerdocker-compose downMedia Files Persistence
Added a named volume
bakerydemo_mediato persist uploaded images and media files:/code/bakerydemo/mediainside the containerFixed Docker Entrypoint Script
Converted
docker-entrypoint.shline endings from CRLF to LF:Removed Conflicting Volume Mount
Removed the
./bakerydemo:/code/bakerydemovolume mount from the app service:Technical Details
Modified
docker-compose.yml:dbservice for PostgreSQL data persistenceappserviceModified
docker-entrypoint.sh:Testing Steps
docker-compose up -ddocker-compose exec app python manage.py migratedocker-compose exec app python manage.py load_initial_datadocker-compose downdocker-compose up -dload_initial_dataImpact
Users can now run
docker-compose downwithout losing:The
load_initial_datamanagement command only needs to be run once during initial setup, not after every container restart.Fixes
Closes #207