2

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
WORKDIR /app
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 -it command give me the following output: enter image description here

3
  • 1
    Try running it with -it flag instead of -d, that should attach you to the standard input/output and may give you a clue as to why the container isn't starting. Commented Oct 24, 2016 at 15:22
  • Sorry for stealth edit, you can't have -d and -it at the same time, just do -it. Commented Oct 24, 2016 at 15:27
  • I just tried with -it command. Could you please help me solving this issue ? Commented Oct 25, 2016 at 12:29

1 Answer 1

6

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 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

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

EXPOSE 80

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

WORKDIR /app
RUN dotnet restore

ENV ASPNETCORE_URLS http://*:5000
EXPOSE 5000

ENTRYPOINT ["dotnet", "run"]

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much. I forgot the ENV ASPNETCORE_URLS http://*:5000 command, that's why i failed. I thought EXPOSE 5000 would be enough
@XavierW. That bit is actually from a deleted answer on this question, glad you're up and running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.