Xavier W. Xavier W. - 9 months ago 78
ASP.NET (C#) Question

Asp.Net Core on Docker

I'm currently trying to launch a Docker component with a ASP.NET Core application.

I use the following repo for my test : https://github.com/aspnet/cli-samples

I ran the following commande without any issue :

git clone https://github.com/aspnet/cli-samples aspnet-Home
cd aspnet-Home/HelloWeb
cat Dockerfile

FROM microsoft/aspnetcore
COPY . .
ENTRYPOINT ["dotnet", "helloweb.dll"]

sudo docker build –t helloweb .
sudo docker run -d helloweb

The image is visible using the
sudo docker images
, but the container doesn't launch and is not visible with
sudo docker ps

enter image description here

And if I browse my website, obsviously I do not see data.
Is the repo not good for my test ? Is there any mistake I do on the docker container creation ?

Running the
command give me the following output:
enter image description here

Answer Source

The error you highlighted is because helloweb.dll you set as the ENTRYPOINT doesn't exist. There could be two reasons for it

1 You didn't build the project yet

In this case you should run dotnet restore from the project home directory, then navigate to HelloWeb directory and run dotnet publish. When I run this command, I see the following:

publish: Published to /code/HelloWeb/bin/Debug/netcoreapp1.0/publish  
Published 1/1 projects successfully

2 You built the project, but the path ENTRYPOINT path is wrong

COPY . . directive will copy everything from the current directory into your app directory. That means HelloWeb.dll will actually be in bin/Debug/netcoreapp1.0/publish/ (or bin/Release/... for release builds).

Option 1: Modify your entrypoint with the full path

ENTRYPOINT ["dotnet", "bin/Debug/netcoreapp1.0/publish/HelloWeb.dll"]

Your application should happily start and serve requests.

Option 2: Modify your COPY directive

Once your project has been published, everything you'll need to run it will be in the publish directory. You could copy the contents of that into the /app directory and your entrypoint will be correct. That would look like this

FROM microsoft/aspnetcore

COPY ./bin/Debug/netcoreapp1.0/publish/ .


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

You will also probably want to add the EXPOSE directive to tell Docker that your container will be listening on port 80.

When that succeeds, you should see (if you run in interactive mode)

docker run -it helloweb   
Hosting environment: Production
Content root path: /app
Now listening on: http://+:80
Application started. Press Ctrl+C to shut down.

You could also use the microsoft/dotnet:latest image instead. That image comes with the SDK installed and a very convenient run command. The Dockerfile would look like this

FROM microsoft/dotnet:latest

COPY . /app

RUN dotnet restore


ENTRYPOINT ["dotnet", "run"]

and you should be able to modify your source and build and run your container.