For anyone else facing this problem, I have found a solution.
In my case, the Dockerfile created with the Powershell command echo “FROM mcr.microsoft.com/hello-world” > Dockerfile had a UTF-16 LE encoding.
I opened vscode and changed it to UTF-8 and the error was gone.