3

I have a .Net Core 3.1.200 that reference another code that is written in .Net Standard 1.3 (shared with .Net Framework apps).

When I try to push image to a docker it fails on all sorts of memory faults. Image was running perfectly till the reference was added. Here is my docker file:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1

COPY bin/publish/ /app-docker-image

WORKDIR /app-docker-image

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

Is there a way to make it work on a Linux docker?

Thanks!

2
  • 1
    can you share the error messages you were seeing? Commented Jul 28, 2020 at 5:17
  • This is the error I get: dotnet[29542]: segfault at 0 ip sp error 4 in libc-2.28.so Commented Jul 28, 2020 at 6:09

1 Answer 1

2

Quick Answer:

Reference the project in your custom .net app. Transfer the app code (along with .NET standard lib dependency inside docker) and build the new image

Explanation:

Your current approach isn't the recommended way of creating container images. You don't copy a pre-built code to the runtime image.

Rather than copying publish folder from host to container, you should transfer the code to the SDK container image.

With the code inside docker run dotnet CLI commands to build/publish the code.

The transfer the published folder from SDK container to runtime container. Your docker file should look like below:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["ConsoleApp1/ConsoleApp1.csproj", "ConsoleApp1/"]
RUN dotnet restore "ConsoleApp1/ConsoleApp1.csproj"
COPY . .
WORKDIR "/src/ConsoleApp1"
RUN dotnet build "ConsoleApp1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ConsoleApp1.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp1.dll"]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! It required some modifications (for example the last FROM command - there is not "base" - changed to publish and it worked)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.