Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with dotnet runtime in docker container #1432

Closed
flor3sc0 opened this issue Nov 10, 2024 · 4 comments
Closed

Error with dotnet runtime in docker container #1432

flor3sc0 opened this issue Nov 10, 2024 · 4 comments

Comments

@flor3sc0
Copy link

Steps to reproduce

Create project

dotnet new worker -n TgBotWorker
dotnet add package Telegram.Bot

Create Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/runtime:8.0
WORKDIR /app
COPY --from=build-env /app/out .

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

Build and run docker container

docker build -t tgworker .
docker run --name tgworker tgworker

Expected behavior

The worker prints a message with the date and time to the console

Actual behavior

Error message

You must install or update .NET to run this application.    

App: /app/TgBotWorker.dll
Architecture: x64
Framework: 'Microsoft.AspNetCore.App', version '8.0.0' (x64)
.NET location: /usr/share/dotnet/

No frameworks were found.

Learn more:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=8.0.0&arch=x64&rid=linux-x64&os=debian.12

Screenshots

Environment data

NuGet Package Version:
<PackageReference Include="Telegram.Bot" Version="22.0.2" />

.NET Version: (e.g. 4.7, Core 1.1, Mono, etc.)
.net 8.0

@Dippere
Copy link

Dippere commented Nov 10, 2024

This issue isn't related to library at all. In this line RUN dotnet publish -c Release -o out add --self-contained true and check info about self-contained apps and not. For issues like this you can ask in telegram chat. I will add full example below for Dockerfile:

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY ["Project.csproj", "./"]
RUN dotnet restore -r linux-x64 "./Project.csproj"

# copy and publish app and libraries
COPY . .
RUN dotnet publish "./Project.csproj" -r linux-x64 -c Release --self-contained true --no-restore -o /app

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime:8.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["./Project"]

Please close this issue.

@flor3sc0
Copy link
Author

Ok, thanks, I'll try that.
But why is everything ok in my case with version 19.0.0? This problem appears starting with version 22

@SoulsideJourney
Copy link

@flor3sc0 That's because since v21 it was added "Microsoft.Extensions.Options.ConfigurationsExtensions" dependency that requieres ASP.NET Core Runtime for work

@BloodShadow174
Copy link
Contributor

I had the same problem, the solution was very simple.
Replace this:
FROM mcr.microsoft.com/dotnet/runtime:8.0
To this:
FROM mcr.microsoft.com/dotnet/aspnet:8.0

wiz0u added a commit to TelegramBots/book that referenced this issue Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants