wish help you to fix your issue You have the right intuition about the difference between build and publish. dotnet build will build the application for local development. One aspect is that the build will assume all dependencies are available via local nuget cache.
I think the issue was by ths following , You should either run your container in the Interactive mode (with -i option). but please note that the background processes will be closed immediately when you run the container so make sure your script is run in the foreground or it simply won't work.
Interactive, Selectable and scrollable Items in Console Application in .NET Core like Yeoman console
I wish did fix the issue. That's because MVC Core is configuring the dependency injection properly, as opposite to the console application. In your console application, you may instantiate your DbContext manually using this:
var builder = new ConfigurationBuilder()
var configuration = builder.Build();
var optionsBuilder = new DbContextOptionsBuilder<SystemDataContext>();
var db = new SystemDataContext(optionsBuilder.Options);
Is it possible to run .NET Core console application silently (hide console window)?