When using Docker, Docker Compose, etc. I’ve found that trying to populate a database by mounting a volume containing the necessary .sql files doesn’t always work. If you’re using PostgreSQL and developing locally, here is a quick command to seed (re-seed) your database.
In your terminal:
1 | cat ./path/to/data.sql | docker exec -i <docker service> psql -U <postgres username> |
In this example SQL file, we’re going to create a DB called ‘orders’. We need to remove any existing instances of our database before populating.
At the top of your SQL file:
1 | -- Make sure db exists |