要在Docker中部署一个C# webserver,您可以按照以下步骤操作:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["MyWebServer.csproj", "."]
RUN dotnet restore "./MyWebServer.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "MyWebServer.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyWebServer.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyWebServer.dll"]
在上面的Dockerfile中,您需要替换“MyWebServer.csproj”和“MyWebServer.dll”为您的实际项目名称。
docker build -t mywebserver .
docker run -d -p 8080:80 mywebserver
这将会在8080端口上启动您的C# webserver。您可以通过访问http://localhost:8080来访问您的webserver。
希望这些步骤能够帮助您在Docker中成功部署一个C# webserver。