DEV Community


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

dcruz1990 profile image Dennis Quesada Cruz ・1 min read

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?

Discussion (2)

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.

dcruz1990 profile image
Dennis Quesada Cruz Author

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.

Forem Open with the Forem app