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
