Run AppTask in Docker?

I’ve started a blank x new vue-vite project, and followed the video. I noticed that there’s a Dockerfile which seems to follow the standard MS format (a build and a runtime image).

The template came with DB Migrations, there’s even a npm script for it in the template:
"postinstall": "cd ../api/myapp && dotnet run --AppTasks=migrate",

How does this combine with Docker? I’m not that experienced with Docker, so I just ran a basic
docker build -t myapp and
docker run -d -p 80:8080 --name myappA myapp

I can now access the template-based application on port 80, and I do get the Vue based front-end, but once it calls Authenticate from the /api, it complains about missing tables, that should probably have been created by the Migrate AppTask.

So how can I run the AppTask in Docker? I see that this has been thought for Docker-Compose (there’s a yaml example file), but is that the only way?

The reason why running the migrations AppTask has been pulled out into a separate step is to prevent deployments when migrations fail as you don’t want your new deployed app that relies on latest Migration schema changes to run when migrations have been rolled back.

So it would already be too late to try run migrations in the deployed Docker app, the strategy we’ve adopted in the templates are to run a sidecar container in Docker compose:

Which is run as a separate step before your App is deployed in GitHub Actions release.yml:

So if the migration Task fails it doesn’t deploy your Docker App, leaving your existing deployed Docker App running whilst you look through the CI logs or Migration table logs to investigate and resolve why it failed.

If you didn’t want the separate CI step and always want to run migrations to run with your Docker App then you don’t need to register AppTasks defined in Configure.Db.Migrations.cs and can just run them when your App starts up, i.e:

var migrator = new Migrator(appHost.Resolve<IDbConnectionFactory>(), 
1 Like

Thanks for explaining the reasoning behind.