skip to Main Content

I’m currently building an example of an API by using .net6 and I’m tracking to use docker to run the API.

My docker file looks like this:

# Grab the app package and create a new build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
# Let's add all the files into the app directory
WORKDIR /app

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]

I created the image by running this command:

 docker build -t binarythistle/dockerapi .    

Now, I’m trying to run the image to create the container:

docker run -p 8000:80 dockerapi  

But, I’m getting the following result:

The command could not be loaded, possibly because:
  * You intended to execute a .NET application:
      The application 'DotNet.Docker.dll' does not exist.
  * You intended to execute a .NET SDK command:
      No .NET SDKs were found.

Download a .NET SDK:
https://aka.ms/dotnet-download

Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found

Does anyone has any idea what can be done to solve this issue?

Site Note: I downloaded the .NET6.0 SDK macOS as recommended but I’m still having an issue. The project that I’m running with .net is a standard api project where the command that allowed me to create this is the following:

dotnet new webapi -n DockerAPI

3

Answers


  1. There’s no DotNet.Docker.dll within that directory that you’re running dotnet.

    The best way to solve this is to shell in to the container you’ve just created

    docker run -it dockerapi bash
    

    -it will make it an interactive processes
    bash will change the ENTRYPOINT to be bash

    once you’ve got a shell then run an ls command and see what files have been copied from the previous layer in the docker build

    ls
    
    Login or Signup to reply.
  2. try running like this

    ENTRYPOINT [ "./DotNet.Docker" ]
    
    Login or Signup to reply.
  3. I was also facing the same issue, however, it got it fixed after replacing below line in the docker file.

    Old:

    ENTRYPOINT ["dotnet", "DotNet.Docker.dll"] 
    

    New:

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

    Use your_application_name.dll in place of SampleWebApplication.dll.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search