Home > OS >  Openshift fails to execute dotnet after apparently successful docker image build?
Openshift fails to execute dotnet after apparently successful docker image build?

Time:08-27

I'm trying to build the project in our GitLab pipeline and then copy it into the Docker container which gets deployed to my company's OpenShift environment.

My dockerfile is below, which does a RUN ls to show that all the files were copied in correctly:

FROM bar.prod.myc.com/myc-docker/myc-ubi8-dotnet60-sdk AS builder
USER root

WORKDIR /App

EXPOSE 5000

RUN dotnet --info

COPY MyApp/bin/publish/ .

RUN pwd
RUN ls

FROM bar.prod.myc.com/myc-docker/myc-ubi8-dotnet60-sdk:latest
ENV ASPNETCORE_ENVIRONMENT="Debug"
ENV WEBSERVER="Kestrel"
ENV ASPNETCORE_URLS=http://0.0.0.0:5000

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

It builds and deploys correctly, but when OpenShift tries to run it the logs show this error:

Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET program, but dotnet-MyApp.dll does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

I've double checked the spelling and case multiple times, so what else could be causing this issue?

CodePudding user response:

Your dockerfile builds two containers:

The first one is:

FROM bar.prod.myc.com/myc-docker/myc-ubi8-dotnet60-sdk AS builder
USER root

WORKDIR /App

EXPOSE 5000

RUN dotnet --info

COPY MyApp/bin/publish/ .

RUN pwd
RUN ls

And the second one is:

FROM bar.prod.myc.com/myc-docker/myc-ubi8-dotnet60-sdk:latest
ENV ASPNETCORE_ENVIRONMENT="Debug"
ENV WEBSERVER="Kestrel"
ENV ASPNETCORE_URLS=http://0.0.0.0:5000

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

The second container is what you are trying to run? It doesn't include a COPY --from=builder .... That means it doesn't actually contain your application at all. It's expected that dotnet complains, because your dll is not present. You can confirm that by doing an ls in your second container:

FROM bar.prod.myc.com/myc-docker/myc-ubi8-dotnet60-sdk:latest
ENV ASPNETCORE_ENVIRONMENT="Debug"
ENV WEBSERVER="Kestrel"
ENV ASPNETCORE_URLS=http://0.0.0.0:5000

RUN pwd
RUN ls

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

Aside: If you have already published your application as framework-dependent, you can probably run it using the smaller registry.access.redhat.com/ubi8/dotnet-60-runtime image.

  • Related