Reputation: 305
Am trying to create a docker image where you can build/publish but also run a .net core website but having a real issue with
image mcr.microsoft.com/dotnet/sdk:5.0
If you build inside a container with that it publishes no problem but when you run you get issues. By contrast if you run with
mcr.microsoft.com/dotnet/aspnet:5.0
then you get no issues, that runs the app fine, but of course you cant use that package to publish or build as its runtime only.
I have done an experiement to run a .net core web app using identical source code and dockerfiles except one is using the sdk and one is using aspnet. Both dockerfiles build an image using pre-built dlls from a publish folder that was generated before. They look like this..
docker file 1
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
#copy dlls from publish into working directory
COPY /publish .
ENTRYPOINT ["dotnet", "/app/Whipover.dll"]
docker file 2
FROM mcr.microsoft.com/dotnet/sdk:5.0
WORKDIR /app
#copy dlls from publish into working directory
COPY /publish .
ENTRYPOINT ["dotnet", "/app/Whipover.dll"]
Docker file 1 image runs the website no problem, Docker file 2 image gives the error.. " Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'."
Do we know why that is? I thought the sdk image is supposed to be able to do everything the aspnet image can do. As for the error I could modify docker file 2 to include
#ENV ASPNETCORE_URLS=http://+:80
#EXPOSE 80 5000
.. which runs the website but then it cant retrieve the contents of wwwroot.. so that would be another issue. Also I dont see why I need to manually expose ports when dockerfile 1 had no problem at all?
Thanks
Upvotes: 0
Views: 1562
Reputation: 305
The solution is to have a multipart dockerfile where you build with the sdk and then run with a runtime different image.
I was under the impression the sdk could do both.
I was looking at an out of date course on pluralsight. This is the best reference to use is https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-5.0
Upvotes: 0