3

All my projects is .NET Core SDK 2.2.

I have 4 projects.

TestData TestConsole TestLogic TestData2.

At startup, I'm setting the Console as the start project and each project has references to each other.

What I wonder is where do I create dockerfile and what should I add to the dockerfile?

Here is my dockerfile current:

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

Error:

skipping project

TestData.csproj TestLogic.csproj TestData2.csproj

was not found.

2
  • Place your docker file to the Solution Items folder (where all your projects exist) and everything should be fine. Commented Mar 15, 2019 at 13:07
  • I tried to put it in the root of the solution. Error: Copy *.cs proj no source files were specified. COPY FAILED. Commented Mar 15, 2019 at 13:10

2 Answers 2

3

To make it efficient you have to copy all the project's .csproj files first and then restore to cache the results. Then copy everything else and publish the project. So your Dockerfile will look similar to

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY aspnetapp/aspnetapp.csproj aspnetapp/
COPY TestData/TestData.csproj TestData/
COPY TestLogic/TestLogic.csproj TestLogic/
COPY TestData2/TestData2.csproj TestData2/
RUN dotnet restore ./aspnetapp/aspnetapp.csproj

# Copy everything else and build
COPY . ./
RUN dotnet publish ./aspnetapp -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

You may want to explicitly copy the projects after restore if you have more projects in the solution to reduce the container build time.

In my project I created a tool that creates COPY directives for main project dependencies from the command line to simplify the process.

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

Comments

2

Try the following:

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

COPY . ./aspnetapp/
WORKDIR /app/aspnetapp
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:aspnetcore-runtime AS runtime
WORKDIR /app
COPY --from=build-env /app/aspnetapp/src/TestConsole/out ./
ENTRYPOINT ["dotnet", "TestConsole.dll"]

10 Comments

I'm getting this error. COPY failed: stat /var/lib/docker/overlay2/cf934d8bdb1a8ffda4a1ca52db81827bf3fcddcf8f296dba9b37a38c82fbd60b/merged/app/aspnetapp/src/testconsole/out: no such file or directory
Try edit this line to: COPY --from=build-env /app/aspnetapp/TestConsole/out ./
I've only installed docker desktop, Error stat '/var/lib/docker/overlay2/bec9381dd84b05faba723a10fe7f452b8e1b084eae900fa00e5d90d4d7bb8042/merged/app/aspnetapp/src/TestConsole/out: no such file or directory'
Remove src from COPY --from=build-env /app/aspnetapp/src/TestConsole/out ./
docker run -d -p 8080:80 --name testconsole testconsole, does this look correct? I can't seem to be able to access the localhost
|

Your Answer

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