0

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

2
  • Is '/app/F:\testfile.png' what is set to inputData.FilePath? So far it seems like this is a URI creation issue, and not a docker-specific issue. If you could provide more information on how FilePath is set, that would help. Commented Mar 1, 2022 at 16:51
  • Sorry no I should have explained better but inputData.FilePath below is received as "F:\\testblob.png" from Rest API body like; { "FilePath" : "F:\\testblob.png" } ... but when client.DownloadFile(new Uri(inputData.FilePath), "test1.png"); or fileBytes = 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. Commented Mar 2, 2022 at 17:56

1 Answer 1

0

I think there might be several issues. First of all from a container you can not access the filesystem. You need to eigther mount a share or copy the testfile in the dockerfile.

The other thing coming to my mind is that the container is running on linux and thus you need to specify the path like so: F:/testfile.png.

If this does not help I would recomment starting the container and looking at its filesystem.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Clemens have provided more details in original post above. Hopefully there is enough to work with there.
Please have a look at the filesystem of your container. You may not acess any file from your host computer which you did not mount or copy into the container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.