Hvaandres
Hvaandres

Reputation: 1005

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

Upvotes: 4

Views: 4114

Answers (4)

Hp93
Hp93

Reputation: 1535

In my case, I messed up the folder path.

I bind a volume to the default path /app.

This volume obviously doesn't contain any .dll file, so .NET cannot run, thus the message: The application '*.dll' does not exist.

Upvotes: 1

It's Anya Pandey
It's Anya Pandey

Reputation: 41

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.

Upvotes: 4

Levan Revazashvili
Levan Revazashvili

Reputation: 119

try running like this

ENTRYPOINT [ "./DotNet.Docker" ]

Upvotes: 1

Kevin Smith
Kevin Smith

Reputation: 14436

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

Upvotes: 2

Related Questions