I'm new to docker and docker compose. To be quiet honest, I'm new to programming in general.
Currently I'm following a course in Web Development with Python (Django) and JavaScript. One of the project hinted that we should try to use docker.
I use docker-compose to start Django server and connect them to a Postgres database. This configuration is copied from Docker documentation in Django
version: "3.9"
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/usr/src/app
ports:
- "8000:8000"
depends_on:
- db
This resulted in a creation of a folder called /data under the root.
Should I add this to the repository?
Should I even use volumes for database? (In the course tutorial, the database part only include:
services:
db:
image: postgres
If you look at the docker documentation for postgres, the volume mount for /var/lib/postgresql/data is to hold the postgres db data even after reboots of the postgres container. ie any DML/DDL changes that you might have done, will be persisted even across reboots of your laptop as well.
Typically, since this can be resurrected by running your migrations, you will want to add this (/data/db) into your .gitignore file. This will also ensure that any of your co-developers are free to make their changes while clicking through the app and not get conflicts of any binary data files that postgres might write to this location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With