.NET Core 3 application cannot connect to database when deployed on a Docker image

I have a .Net Core 3.0 project that I’ve been trying to deploy to a docker container that cannot seem to connect to the database context ever since I upgraded from Core 2.2 to Core 3.0. I can run the project locally just fine, but when it’s deployed to a Docker container, the app hangs at the first instance where I call my context, which happens to be in my main() method in my Program.cs:

    public static void Main(string[] args)
    {
        IHost host = CreateHostBuilder(args).Build();

        using (IServiceScope scope = host.Services.CreateScope())
        {
            IServiceProvider services = scope.ServiceProvider;

            try
            {
                VideoContext context = services.GetRequiredService<VideoContext>();
                // my project never makes it past the following line:
                context.Database.Migrate();
                SeedData.Initialize(services);
            }
            catch (Exception e)
            {
                Console.WriteLine("error");
                IErrorLogService logger = services.GetRequiredService<IErrorLogService>();
                logger.LogError(e);
            }
        }

        host.Run();
    }  

The app will hang indefinitely and never make it past the context.Database.Migrate() method. There isn’t even a SQL Connection Timeout exception thrown, so it has to be something before it even tries to make the SQL connection. My docker container doesn’t throw any errors either.

Here’s my dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0
WORKDIR /app
# Make sure this folder exists
RUN mkdir -p /app/PrivateAssets/Attachments
COPY --from=build-env /app/out .
COPY secrets.json /root/.microsoft/usersecrets/44EFF06F-8817-4BCE-9CD3-872D7E944C3D/secrets.json
EXPOSE 80
ENTRYPOINT ["dotnet", "JPLTube.dll"]

Any ideas as to why my app hangs indefinitely? Please let me know if there’s any other files needed to debug. I figured the only thing necessary was the dockerfile because the whole project runs fine on my local machine. Thank you!

Source: StackOverflow