0

Let's take an example of dotnet application code

  • I have an application code present at

    D:\eshop\DotneteShopOnWeb\src\Web\Application.sln

  • and I have multiple projects in the "Application.sln" like Web, API, Test

  • every project is having its own Dockerfile like

    D:\eshop\DotneteShopOnWeb\src\Web>Dockerfile

The Dockerfile is as below

FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /app

COPY *.sln .
COPY . .
WORKDIR /app/src/Web
RUN dotnet restore

RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS runtime
WORKDIR /app
COPY --from=build /app/src/Web/out ./

ENV ASPNETCORE_ENVIRONMENT Development

ENTRYPOINT ["dotnet", "Web.dll"]

I am executing the docker build command Dockerfile location.

I have also tried docker build -t dotnetcore-eshop-mvc-manual -f src/Web/Dockerfile . from D:\eshop\DotneteShopOnWeb>

I am getting errors in RUN dotnet restore as the sln file is not getting copied into the work directory.

Please let me know what modification I need in COPY to copy content from the previous directory.

Eddie
  • 581
  • 3
  • 11
  • 20
  • Does this answer your question? [Docker: adding a file from a parent directory](https://stackoverflow.com/questions/24537340/docker-adding-a-file-from-a-parent-directory) – omajid Jan 29 '21 at 15:03

1 Answers1

0

you are changing the working directory before restoring. I mean that your .sln files are in the path /app but your restoring is executed inside /app/src/Web location. you should do something like this to copy .sln files.

COPY *.sln .
COPY . .
WORKDIR /app/src/Web
COPY . .

RUN dotnet restore
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS runtime
WORKDIR /app
COPY --from=build /app/src/Web/out ./

ENV ASPNETCORE_ENVIRONMENT Development

ENTRYPOINT ["dotnet", "Web.dll"]
Amir
  • 1,214
  • 7
  • 10
  • :- Thanks for the reply. The solution that you have suggested is not able to copy the content from the previous directory. what I want to do is like `cd ../..` and whatever is there I want to copy them all. – Eddie Jan 29 '21 at 14:13
  • There is no need to copy from previous directory. I guess your problem can be resolved in many ways! I changed my answer to another way but it’s not best practice – Amir Jan 29 '21 at 16:12
  • :- I tried your solution. It's still the same. I believe the .sln folder which is present in the previous directory has to be copied, else the `dotnet restore` will give an error saying `> [build 5/6] RUN dotnet restore: #10 1.470 MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.` – Eddie Feb 01 '21 at 13:57
  • If you have any Whatsapp or Google Hangout mail me your account at a.solhi@alibaba.ir. I will help you to resolve your problem. – Amir Feb 01 '21 at 14:17