'Accessing Files with .net on Linux Containers in Windows
I have the following simple app
var fileCount = System.IO.Directory.GetFiles(@"/home/joe").Count();
Console.WriteLine($"Hello,! There are {fileCount} files.-");
And a dockerfile
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 . ./
RUN dotnet publish HelloDocker -c Release -o publish
FROM base AS final
COPY --from=build src/publish .
ENTRYPOINT ["dotnet", "HelloDocker.dll"]
I am attempting to run this with variations of the following command based on search results.
docker run -i test:nobase -v c:/temp:/home/joe
but keep getting a System.IO.DirectoryNotFoundException saying that Could not find a part of the path '/home/joe'.
How should the correct path to c:\temp be shared and accessed from my app when running in a container?
Solution 1:[1]
docker run arguments before the image name are docker arguments and arguments after the image name become a command for the container, overriding any CMD statements in the image.
A volume mapping is a docker parameter, so it needs to go before the image name like this
docker run -i -v c:/temp:/home/joe test:nobase
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hans Kilian |
