I'm new to Docker and am having an issue with reading file paths using either client.DownloadFile(new Uri(inputData.FilePath), "test1.png"); to download the file or var fileBytes = await File.ReadAllBytesAsync(inputData.FilePath); to read the file bytes with error;
System.Net.WebException: Could not find file '/app/F:\testfile.png'.
---> System.Net.WebException: Could not find file '/app/F:\testfile.png'.
---> System.IO.FileNotFoundException: Could not find file '/app/F:\testfile.png'.
File name: '/app/F:\testfile.png'
Updated: The inputData.FilePath field below is received as "F:\\testblob.png" correctly from Rest API body so no issue there it's just when either line reading file path are called using Docker only then /app/ gets appended at the start and I don't know why.
My docker-compose file is as per below.
version: '3.4'
services:
testdockerproject:
image: testdockerproject
build:
context: .
dockerfile: ./Dockerfile
ports:
- 7400:80
My Dockerfile is;
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
# Copy everything and build
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["testdockerproject.csproj", "./"]
RUN dotnet restore "testdockerproject.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "testdockerproject.csproj" -c Release -o /app/build
# Publish the binaries
FROM build AS publish
RUN dotnet publish "testdockerproject.csproj" -c Release -o /app/publish
# Build image
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "testdockerproject.dll"]
As mentioned I'm a complete novice to Docker so very unsure what else I need to do. If anyone can provide any answers would be really appreciated.
Updated after @Clemens Comment: I had tried to a Volume Mount like below but no success so maybe I'm targeting the wrong place or doing something incorrectly.
1. Create Volume docker volume create testvolume
2. Inspect Volume docker volume inspect testvolume
[ { "CreatedAt": "2022-02-28T17:02:27Z", "Driver": "local", "Labels": {}, "Mountpoint": "/var/lib/docker/volumes/testvolume/_data", "Name": "testvolume", "Options": {}, "Scope": "local" } ]
3. Start a Container with a Volume docker run -d --name testcontainer --mount source=testvolume,target=/app nginx:latest
"Mounts": [ { "Type": "volume", "Name": "testvolume", "Source": "/var/lib/docker/volumes/testvolume/_data", "Destination": "/app", "Driver": "local", "Mode": "z", "RW": true, "Propagation": ""
4. Update docker-compose.yml
services: testdockerproject: image: testdockerproject build: context: . dockerfile: ./Dockerfile ports: - 5000:5000 volumes: - testvolume:/var/lib/docker/volumes/testvolume/_data volumes: testvolume:
5. Start a service with volumes docker service create -d --replicas=4 --name testvolume-service --mount source=testvolume,target=/app nginx:latest
inputData.FilePathbelow is received as"F:\\testblob.png"from Rest API body like;{ "FilePath" : "F:\\testblob.png" }... but whenclient.DownloadFile(new Uri(inputData.FilePath), "test1.png");orfileBytes = await File.ReadAllBytesAsync(inputData.FilePath);are called then/app/gets appended onto filepath. Have tried different ways of sending filepath with single/double backslashes/forwardslashes, prefixing with file: but always gets appended with /app. Works fine on IIS, just not with with Docker.