DEV Community

Dennis Quesada Cruz
Dennis Quesada Cruz

Posted on

What's the proper way to run a DotNet ef migrations when deploying with Docker

Hello Devs, im looking for the best aproach to update the app database (DotNet WebApi) when deploying to a Docker Container. This is what i have so far:
1 - Tried to run a migration inside the startup class using context.Database.Migrate(), for some reason didnt work.
2 - Compose build and up, then manually 😅 run bash inside the aspnet container, install ef tool, add the migration and update database.
3 - Get the SQL script runing DotNet ef migrations script and putting it inside a seed. SQL on the Postgres container.

Im wondering if there is a automatic way to do that?

Top comments (2)

Collapse
 
chekkan profile image
Harish Babu

I have blogged about entity framework core database migration although on AWS ECS. But, I assume that something similar can be applied to other container orchestration platforms.

Collapse
 
dcruz1990 profile image
Dennis Quesada Cruz

Thanks Harish! Im going to try that way, using a extra Dockerfile that runs the migration, the key here is wait for PostgreSQl and then runs, otherwise allways fails. Regards.