Reputation: 1360
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
:
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:
Upvotes: 2
Views: 2321
Reputation: 20246
The error you highlighted is because helloweb.dll
you set as the ENTRYPOINT
doesn't exist. There could be two reasons for it
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
ENTRYPOINT
path is wrongCOPY . .
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.
Upvotes: 6