0

I'm using postgres with docker and git

docker-compose.yml

version: '3'

services:
  db:
    image: postgres: 12.7
    volumes:
      - ./data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=xxxx

tree

.
├── docker-compose.yml
└── data
    └── .gitignore

I need a gitignore file to add folder to repository(how-do-i-add-an-empty-directory-to-a-git-repository), but postgres will raise an error because of non-empty folder

initdb: error: directory "/var/lib/postgres/data" exists but is not empty

Is there any solution for this?

I've try to run a script to clear gitignore file before postgres launched, but I failed to run it in commands

gitignore=$PGDATA/.gitignore
git_keep=$PGDATA/.gitkeep
if [ -f "$gitignore" ] ; then
    rm "$gitignore"
fi
if [ -f "$git_keep" ] ; then
    rm "$git_keep"
fi
RockyDon
  • 1
  • 1
  • Can you move the gitignore file to top directory as docker-compose.yml ? – Addell El-haddad Apr 23 '23 at 04:12
  • The .gitignore exists because empty directories can't be tracked by git (git only tracks files). It won't have the same effect if not in that directory. I was going to suggest yesterday having a makefile / readme instructions for the one-time operation of creating that directory, or using a volume maybe? I didn't like those solutions. – erik258 Apr 23 '23 at 12:53

0 Answers0