If you're starting with Part 2 or later, don't forget to run the following commands:
# Create a static directory
$ mkdir -p server/static# Build all of the Docker containers
$ docker-compose up -d --build# Create a superuser
$ docker-compose exec server python manage.py createsuperuser# Load all of the fixture data
$ docker-compose exec server \
python manage.py loaddata \
catalog/fixtures/wines.json \
--app catalog \
--format jsonLoading the fixture data will take a long time (at least 10 minutes) because Django is copying 150,000+ records. Each record spawns an update to the catalog_winesearchword table as well as updates the search_vector field on the catalog_wine table. This all happens in a single transaction. After you do this once, you should consider dumping the database so that you can restore it later if you need to.
First, run the following command to dump the database:
$ docker-compose exec database pg_dump -U perusable -f perusable.sql -F plain perusableThe database backup file will be on the container and you'll need to copy it to your host machine.
First, find the database's container ID:
$ docker container lsNext, use the container ID to copy the database dump to your host:
# This will copy the file to the host directory you are running the command from
# Replace <container_id> with your own
$ docker cp <container_id>:perusable.sql .Delete the backup file from your container:
$ docker-compose exec database bash
root@<container_id>:/# rm perusable.sql
root@<container_id>:/# exitAlternatively, you can dump the database to stdout and pipe the output into a file on your host machine. Use gzip to compress the data:
$ docker-compose exec database pg_dump -U perusable perusable | gzip > perusable.gzTo restore, first copy the backup from your host to the container:
# This will copy the file to the /data directory in the container
# Replace <container_id> with your own
$ docker cp perusable.sql <container_id>:/dataThen, drop the database:
$ docker-compose exec database dropdb perusable -U perusableFinally, restore the database:
# Specifying the file will create the database from scratch
$ docker-compose exec database pg_restore -U perusable -f /data/perusable.sqlNOTE
In practice, restoring the database with
pg_restoretakes just as long (if not longer) as loading the fixtures through Django.