Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running docker containers with .net6

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
like image 708
Hvaandres Avatar asked Oct 23 '25 17:10

Hvaandres


1 Answers

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.

like image 63
It's Anya Pandey Avatar answered Oct 26 '25 06:10

It's Anya Pandey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!