0

I have created a c# console application in .net6.0 which will reads a CSV file .

'''

static async Task<int> Main(string[] args)
    {
       var pro = new Option<string>(
           name: "--project",
           description: "Please provide the Project name")
        { IsRequired = true };

        var path = new Option<string>(
           name: "--csvpath",
           description: "Provide CSV File path (example:C:/temp/asd.csv)")
        { IsRequired = true };

        var rootCommand = new RootCommand("Root for Command Line Arguments")
            {
                pro,
                path
            };          


        rootCommand.SetHandler(async
       (string pro, string path) =>
        {
            await ReadInputData(pro,path);
        },
           pro, path);

        return await rootCommand.InvokeAsync(args);
    }

    internal static async Task ReadInputData(string pro, string path)
    {
        Console.WriteLine(pro);
        Console.WriteLine(path.Name);
        string[] lines = System.IO.File.ReadAllLines(path);
        foreach (string line in lines)
                {
                    string[] columns = line.Split(',');
                    foreach (string rName in columns)
                    {
                        Console.WriteLine("Processing Entry : " + rName );
                    }
                }
    }

'''

This code runs fine ...I want to run this code using docker container so I added Dockerfile as below:

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["consoleproj01/consoleproj01.csproj", "consoleproj01/"]
RUN dotnet restore "consoleproj01/consoleproj01.csproj"
COPY . .
WORKDIR "/src/consoleproj01"
RUN dotnet build "consoleproj01.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "consoleproj01.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "consoleproj01.dll"]

I can create the local docker container successfully using

docker build -t myconsole0328 .

But when I run the container with file path as parameter I am getting below error

docker run myconsole0328 --project testpoject --repocsvpath C:/temp/test.csv

Error : Unhandled exception: System.Exception: Error while processing files : Could not find a part of the path '/app/C:/temp/test.csv'.

Please suggest how can I pass the local path to the docker container.

Piyush
  • 251
  • 1
  • 7
  • 18
  • Duplicate explains what you need to get it working. Note that you can't use Windows paths on Linux... so either use Linux paths or Windows container. – Alexei Levenkov Mar 28 '22 at 22:26

0 Answers0