How find file in Docker?

This is my Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
EXPOSE 80

COPY TotechsThunder.sln TotechsThunder.sln
COPY mock/programminglanguages/programminglanguage.js mock/programminglanguages/programminglanguage.js

RUN dotnet restore TotechsThunder.sln

COPY src/Technologies src/Technologies
COPY src/Contracts src/Contracts
WORKDIR /app/src/Technologies
RUN dotnet publish -c Release -o /app/src/out

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/src/out .
ENTRYPOINT [ "dotnet", "Technologies.dll" ]

I’m having trouble with the programminglanguage.js file. This file contains master data, which my ASP.NET Core app uses during initialization to seed data into the database migration. Everything works fine in my development environment, but when I run the project in a Docker environment, the file can't be found.

When I run docker compose build, the service builds successfully. However, when the project runs in Docker, I encounter the following error:

2024-09-21 04:40:15 Unhandled exception. System.IO.FileNotFoundException: Could not find file '/app/..\..\..\..\..\mock\programminglanguages\programminglanguage.js'

Here’s the code I’m using to read the file for seeding during migration:
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = @"..\..\..\..\..\mock\programminglanguages\programminglanguage.js";
string fullPath = Path.GetFullPath(Path.Combine(baseDir, relativePath));

In Docker, the issue seems to stem from the relative file path not being resolved correctly. I’d appreciate any help in resolving this so the app can find the file in the Docker environment.
Was this page helpful?