© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
7 replies
TotechsStrypper

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" ]
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
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
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'
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));
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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ ❔ Docker-Compose cannot find Dockerfile
C#CC# / help
4y ago
File logs and docker
C#CC# / help
4y ago
✅ Could not find file
C#CC# / help
2mo ago
Find file duplicates | Optimize
C#CC# / help
4y ago