简体   繁体   中英

How to build .Net core application in Docker?

I am working on.Net core application. I am trying to build application using docker container. Below is my file structure.

Root Folder

-MerchWebServices
  -MerchWebServices.sln
  -Dockerfile
  -MWS.AspNetCoreApis
    -bin
    -obj
    -out
    -MWS.AspNetCoreApis

Below is my dockerfile

#FROM microsoft/dotnet:2.1-runtime
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app

COPY MWS.AspNetCoreApis/out .

ENV ASPNETCORE_URLS http://*:44332
EXPOSE 44332

COPY scripts/entrypoint.sh entrypoint.sh
RUN chmod +x /app/entrypoint.sh
CMD tail -f /dev/null
ENTRYPOINT ["dotnet", "MWS.AspNetCoreApis.dll"]

Using below command I am building my application.

docker build -t merchwebservices .

After running above command, image gets created successfully. After that I am running below command.

docker run -p 44332:44332 -d  merchwebservices

I am able to run this command. My container is running now. I am not able to run the web application on

https://localhost:44332/swagger/index.html

I am not sure why I am not able to run the application now. Can someone help me to fix this issue? Any help would be appreciated. Thanks.

First make sure you container is running by inspecting docker ps output.

Then try to access http://localhost:44332/swagger/index.html .

If your app doesn't require any certificate, no need to use https

If it doesn't work inspect docker logs -f container_id output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM