简体   繁体   English

Docker如何构建.Net核心应用?

[英]How to build .Net core application in Docker?

I am working on.Net core application.我正在开发.Net 核心应用程序。 I am trying to build application using docker container.我正在尝试使用 docker 容器构建应用程序。 Below is my file structure.下面是我的文件结构。

Root Folder根文件夹

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

Below is my dockerfile下面是我的 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我无法运行 web 应用程序

https://localhost:44332/swagger/index.html 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.首先通过检查docker ps output 确保您的容器正在运行。

Then try to access http://localhost:44332/swagger/index.html .然后尝试访问http://localhost:44332/swagger/index.html

If your app doesn't require any certificate, no need to use https如果您的应用不需要任何证书,则无需使用https

If it doesn't work inspect docker logs -f container_id output如果它不起作用检查docker logs -f container_id output

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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