I have a created a .net 5 based service. This service works well locally. I am trying to put this into a docker container. However I am unable to connect to it. Service is running using Kestrel configured for 8080
My Dockerfile is fairly straight forward
FROM mcr.microsoft.com/dotnet/aspnet:5.0 #msft image
COPY ./bin/debug/net5.0/ . #local items
EXPOSE 8080
ENTRYPOINT [dotnet, myservice.dll]
Command used to run the service
docker run -it -p 8080:8080 myservice
I have created an image and when I run the above image with -it
flag I can see the service is executed. On inspecting/exporting of the container I can also see some application log files generated, indicating service is running successfully. When I run the swagger endpoint by executing curl inside container I do get the swagger UI HTML page.
However when I run this from my actual machine it doesn't seem to connect to any of the endpoints. I have run the image using -p 8080:8080
so it should respond on same port. I have tried using random local port maps, so certainly ports are not blocked.
I have also checked running another container based services on port 8080 but I am able to access the same, so definitely port is not blocked.
Not sure what am I missing here. Setup is pretty simple since its just a dummy service for testing with one swagger endpoint and another weatherforecast endpoint that comes with .net template.
By default the container will be listening internally on port 80 unless you have overridden that using the
ASPNETCORE_URLS
environment variable.EXPOSE
in the Docker file doesn't do anything but document the ports intended to be used.Try to run it with
-p 8080:80
which will map port 8080 on the local machine to port 80 in the container.