net core project. I have successfully build the project. Below is my dockerfile.
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 4040
EXPOSE 5050
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["MWS.AspNetCoreApis/MWS.AspNetCoreApis.csproj", "MWS.AspNetCoreApis/"]
RUN dotnet restore "MWS.AspNetCoreApis/MWS.AspNetCoreApis.csproj"
COPY . .
WORKDIR "/src/MWS.AspNetCoreApis"
RUN dotnet build "MWS.AspNetCoreApis.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "MWS.AspNetCoreApis.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
CMD tail -f /dev/null
ENTRYPOINT ["dotnet", "MWS.AspNetCoreApis.dll"]
I build my application as docker build -t locationservices . Here I build my image. Then when I run my image using docker run -d locationservices it gives some long id. When I try to hit http://localhost:40/swagger/index.html or http://localhost:5050/swagger/index.html my web page doesnt open.
When I run >docker run -it locationservices I get below message.
Hosting environment: Production Content root path: /app Now listening on: http://[::]:80 Application started. Press Ctrl+C to shut down.
But I am not able to hit my application using any of the below urls
http://localhost:5050/swagger/index.html
http://localhost:4040/swagger/index.html
http://localhost:80/swagger/index.html
can someone help me to figure out the issue. Any help would be appreciated. Thanks
I am little late to this question.
But the actual problem is that you are telling docker what ports to expose but they don't match the port that ASP.NET Core is listening on.
You need to add a Environment Variable to the Dockerfile that matches your exposed ports like this.
EXPOSE 4040
ENV ASPNETCORE_URLS=http://*:4040
The last line of the file:
ENTRYPOINT ["dotnet", "myapp.dll"]
Then run the container using -p 4040:4040 that way it maps the port to the "outside" world.
You can also add docker container run arguments directly into the .csproj file:
<PropertyGroup>
<DockerfileRunArguments>-p "4040:443" -p "5050:80"</DockerfileRunArguments>
</PropertyGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With