This area contains scripts for running the website database locally in a Docker container.
Install Docker Desktop. This should provide the docker
and docker-compose
commands in your terminal. If docker-compose
is missing, try docker compose
instead.
Once Docker Desktop is installed and available via the command line, you can run the following command to start the database, using the -f
flag to specify the location of the docker-compose.yml
file:
docker-compose -f docker/docker-compose.yml up -d
This command will start a PostgreSQL database in a Docker container. The database will be available at localhost:5432
with the username postgres
and password supersecret
.
Create (or update) a .env
file in the root of project to instruct prisma
where to find the database, using the following environment variables:
# Database
POSTGRES_PRISMA_URL="postgresql://postgres:supersecret@localhost:5432/mydb"
POSTGRES_URL_NON_POOLING="postgresql://postgres:supersecret@localhost:5432/mydb"
On first launch Docker will automatically allocate a new volume to persist the database data. On subsequent launches, this volume will be remounted, retaining the data between sessions.
Initially (or if you reset this volume), you'll need to load the database schema and seed data. You can do this by running the following prisma commands:
npx prisma db push
npx prisma db seed
After the database is created and seeded, you can run the website locally to interact with the database.
To stop the database and kill the associated containers, run the following command:
docker-compose -f docker/docker-compose.yml down