Search code examples
.netdockercontainers

File.ReadAllBytes execution hangs in Docker container


This is .Net framework 4.7.2 console app, build platform x64, build in release mode.

OS Windows 10, Docker desktop 2.1.0.5

When running in windows container, the program hangs at File.ReadAllBytes, while reading a 130 MB binary file. This file copied into assembly folder, also get copied into container. File.Exists verified the file is there. The program runs fine to the end when running directly in command prompt, outside container.

Please help.

Dockerfile

FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803

ARG source

WORKDIR /app

COPY ${source:-bin/Release} .

CMD ["fileread-docker.exe"]

Code

{
    class Program
    {
        static void Main(string[] args)
        {
            var path = Path.Combine("folder", "a.abc");
            Console.WriteLine($"Read file from {path}");
            if (File.Exists(path))
            {
                Console.WriteLine($"File exist at {path}");
                var file = File.ReadAllBytes(path);
                Console.WriteLine($"File has been read at {path}");
            }
            else
            {
                Console.WriteLine($"File not exist at {path}");
            }
        }
    }
}
'''



Solution

  • It turns out it's base image issue.

    It's working after I switch from

    FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803

    to

    FROM mcr.microsoft.com/dotnet/framework/runtime:4.8

    New base image is ridiculously 14 GB big. Previously was 6.4GB.

    Anyway, this new base image works as expected. Previous image was copied from one sample code.