Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I include /data folder created by docker-compose to Git?

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.

  1. Should I add this to the repository?

  2. Should I even use volumes for database? (In the course tutorial, the database part only include:

     services:
        db:
          image: postgres
    
like image 576
Sariyanta Made Avatar asked Aug 28 '26 10:08

Sariyanta Made


1 Answers

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.

like image 81
Vijay Raghavan Aravamudhan Avatar answered Aug 30 '26 04:08

Vijay Raghavan Aravamudhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!