1

I have a .NET core 5.0 ASPNET Web API application. This application runs perfectly locally on Visual Studio.

Now I am trying to publish the self contained app using following command:

dotnet publish -c release testdb.sln --framework net5.0 --runtime linux-x64 /p:DebugType=None /p:DebugSymbols=false --nologo --self-contained true -v m

I am trying to run it over a Red Hat Linux image (image details below):

NAME="Red Hat Enterprise Linux Server"
VERSION="7.6 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.6"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.6 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.6:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.6
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.6"
Red Hat Enterprise Linux Server release 7.6 (Maipo)
Red Hat Enterprise Linux Server release 7.6 (Maipo)

This is how my docker file looks like:

FROM testrepo.net/images/base/rhel:7.6

#published code is copied inside redhat folder
COPY redhat/  APP/
WORKDIR APP
RUN chmod +x /APP
RUN chmod +x testdb.dll
RUN chmod 777 /APP

ENTRYPOINT "./testdb.dll"

When I run this this image, I get error: ./testdb.dll: cannot execute binary file

I am not sure if this is due to invalid runtime I specified during publish command or something else.

SharpCoder
  • 18,279
  • 43
  • 153
  • 249
  • 2
    The error is correct - you can't just run a dll. What you need to do instead is run `dotnet testdb.dll`. this means your base docker image will need to have the dotnet cli installed (or you will need to install it as part of your dockerfile - most people use the MS provided images though: https://hub.docker.com/_/microsoft-dotnet-runtime/) – RB. Dec 22 '21 at 22:07
  • @RB. How do I fix it? This is a Linux image without aspnet runtime. So I cannot say ~ENTRYPOINT ["dotnet","testdb.dll"]~ How can I fix this ? – SharpCoder Dec 22 '21 at 22:09
  • Sorry - i was on mobile and accidentally clicked save. I've answered your question in my original comment now :) use an ASP.Net base image for an asp.net application of course - MS provide images for all occasions :) – RB. Dec 22 '21 at 22:10
  • @RB. Since this is a self contained image, shouldn't I can run the app without dotnet cli or dotnet runtime ? – SharpCoder Dec 22 '21 at 22:11
  • Oh, sorry - I missed that detail. It should also have created a file called `testdb` (no extension) - that's the executable - you run that. Apologies for not reading the question properly! – RB. Dec 22 '21 at 22:13
  • See here for example https://stackoverflow.com/a/40230574/15393 – RB. Dec 22 '21 at 22:14
  • changed `RUN chmod +x testdb.dll` to `RUN chmod +x testdb` and changed `ENTRYPOINT "./testdb.dll"` to `ENTRYPOINT "./testdb"` these changes helped. But Now I am getting another error : `Process terminated. Couldn't find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.` I will investigate further. Thank you – SharpCoder Dec 22 '21 at 22:22
  • @SharpCoder check out: https://stackoverflow.com/questions/59119904/process-terminated-couldnt-find-a-valid-icu-package-installed-on-the-system-in to fix issue with Globalization. – akseli Dec 22 '21 at 22:29
  • @akseli : I googled and found same fix and its working :) Thank you – SharpCoder Dec 22 '21 at 22:35
  • @RB. Thank you !! Add your solution as answer – SharpCoder Dec 22 '21 at 22:35

1 Answers1

0

changed RUN chmod +x testdb.dll to RUN chmod +x testdb and changed ENTRYPOINT "./testdb.dll" to ENTRYPOINT "./testdb"

With these two changes I was able to fix the issue.

SharpCoder
  • 18,279
  • 43
  • 153
  • 249