I have a project in docker in which I have been struggling to generate some files from the dockerfile o docker-compose files.
I have a dockerized Django project with the following structure.
assets/
app/
db/
.gitignore (ignoring all files of the folder)
db.sqlite3
docker-compose.yml
Dockerfile
For the purpose of the post I just wrote a general structure to give an idea of how is the project and what I want to do.
What I was trying to do was to mount the database file as a volume (type: bind) but didn't work. What I did was to treat the folder db as a volume folder. Until here all works fine.
What I want to do is to generate the db.sqlite3 file when does not exist, run the migrations and run the command python manage.py collectstatic --noinput.
I tried creating an entrypoint file:
#/bin/sh
python manage.py collectstatic --noinput
db=/code/db/db.sqlite3
if [ ! -f "$db" ]; then
touch "$db"
fi
python manage.py migrate
I tried to call this file with ENTRYPOINT and CMD statement in the Dockerfile and none of them work. I also tried to run the command touch from the Dockerfile and the result was the same.