1

I have a Dockerfile that builds and publishes an application to a container like this

FROM mcr.microsoft.com/dotnet/sdk:5.0 as builder
COPY . ./
RUN dotnet publish Project -c Release -o ./publish

FROM mcr.microsoft.com/dotnet/runtime:5.0 as runner
COPY --from=builder  /publish .
WORKDIR data
ENTRYPOINT ["dotnet", "../Project.dll"]

Building the image and running the container works on Windows, but does not work on Ubuntu server.

project_1  | Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly '/Project.dll'. The system cannot find the file specified.
project_1  |
project_1  | File name: '/Project.dll'

I think the problem is in specifying the argument for dotnet as ../Project.dll, because the shell expands this to /Project.dll and dotnet does not understand Linux paths. Is there a way to fix this?

I'm a beginner to Docker, maybe I'm missing something (shouldn't Docker work the same on every platform?)

EDIT: running dotnet Project.dll from bash in the container inside the parent directory produces the same exact output

Brett Caswell
  • 1,486
  • 1
  • 13
  • 25
Sorashi
  • 931
  • 2
  • 9
  • 32
  • There is no shell involved here. If you look inside the built image (change `ENTRYPOINT` to `CMD`, then `docker run --rm -it your-image sh`) is the file there? – David Maze Feb 28 '21 at 14:35
  • you aren't doing an absolute path here, you're doing a relative one in ENTRYPOINT. title needs to be corrected. – Brett Caswell Feb 28 '21 at 14:37
  • @DavidMaze yes, the file is there – Sorashi Feb 28 '21 at 14:39
  • @DavidMaze running `dotnet ../Project.dll` from sh produces the same exception, although I can see the file ../Project.dll using ls from sh – Sorashi Feb 28 '21 at 14:44

1 Answers1

1

Turned out to be a permission problem, and the application must be in a subfolder (not in the root folder), see https://docs.docker.com/engine/examples/dotnetcore/

FROM mcr.microsoft.com/dotnet/sdk:5.0 as builder
WORKDIR /app
COPY . ./
RUN dotnet publish Project -c Release -o ./publish

FROM mcr.microsoft.com/dotnet/runtime:5.0 as runner
WORKDIR /app
COPY --from=builder  /app/publish .
WORKDIR /app/data
CMD ../Project
Sorashi
  • 931
  • 2
  • 9
  • 32