要在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。