Inconsistent CSRF token missing error in Flask app

I’m inconsistently receiving “CSRF token is missing” error when making POST request with Flask app deployed and run on a Docker container. For an exact same request sometimes the app accepts the request, sometimes it doesn’t.
When I run the app without container (executing flask run) the request works consistently with no error.

I’m new to Docker so would love to learn more.

OS Version: macOS Catalina (10.15)
Flask version 1.0.2
Docker version 2.1.0.2

An example request:
curl -X POST -H “X-CSRFToken: IjQwNWQ2NDNlZTc0ZDQ5N2RjOWVkNDkxNzA2NmQyZDVjY2E0N2RjYWIi.EJuftA.8T6qSDltggybSruWG7ihoFJum9E” -H “Cookie: session=eyJjc3JmX3Rva2VuIjoiNDA1ZDY0M2VlNzRkNDk3ZGM5ZWQ0OTE3MDY2ZDJkNWNjYTQ3ZGNhYiJ9.EJuftA.cSii-qKT0XktAiNf2rMBkQbBoIE” -F hed_strings=’{“hed_strings”: {“1”: {“type”:“event row”, “hed_string”: “Invalid/Tag”},“2”: {“type”:“event row”, “hed_string”:“Item/Object/Car”}}};type=application/json’ -v http://localhost:8080/eegsubmit

After debugging for awhile I found out that this is caused by the the Flask app was being constantly restarted when deployed in a container. Each time the app restarts, it generate a new secret key (as I set the key to be randomly generated), which is used to sign session cookie and thus also the csrf token. The restart can happen in between API calls, which makes the csrf token/session cookie of previous call invalid for the subsequent call.
I have created a work around yet I still don’t understand why the container keep restarting like that.