Hey, I’ve been playing around with docker to get a grasp of several concepts and I’ve run into a snag. I’m trying to setup an application similar to one found on the real python blog. I will post links to both that and my source code (cant post them in OP due to limit on links).
For my proposes I would like to add initial data to the database. I looked around for a good way to do this but didn’t find much so I settled on using a simple python script to test out how to do that. This is simply a proof of concept script and I will be adding much more once I get the concept working.
#test.py from app import db from models import * t = Post("Hello 3") db.session.add(t) db.session.commit()
When I set up the environment via docker-compose I start everything fresh (by rm’ing all docker containters) to make sure that no data persists. My startup process can be seen here. When i view the app after this process instead of seeing the single entry of “Hello 3” I see several. I have tested this multiple times and seen differing amounts each time, and in no particular order. I’ve seen numbers of like entries ranging from 3-6. Example.
Does anybody know why this happens? If not is there a better way to add initial data to the app at startup?