如何在docker服务器核心中运行.net 6 api
我想在同一个 docker 镜像中运行 .net 6 api、java 运行时和 nodejs。我在 servercore docker 镜像中安装了 java,它按照我的预期运行。我在 aspnet docker 映像中部署了 .net 6,然后它就工作了。但我无法在同一个 servercore docker 映像中部署 .net 6 api 和 java。如何在服务器核心映像中部署 .net 6 api?
更新:
FROM mcr.microsoft.com/windows/servercore:ltsc2022-amd64 as base
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
## Install .net
RUN Invoke-WebRequest -OutFile dotnet-sdk-6.0.102-win.exe https://download.visualstudio.microsoft.com/download/pr/fb14ba65-a9c9-49ce-9106-d0388b35ae1b/7bbfe92fb68e0c9330c9106b5c55869d/dotnet-sdk-6.0.102-win-x64.exe; \
Start-Process "dotnet-sdk-6.0.102-win.exe" -ArgumentList "/passive" -wait -Passthru; \
Remove-Item -Force dotnet-sdk-6.0.102-win.exe
## Install Node
ADD https://nodejs.org/dist/v16.14.0/node-v16.14.0-win-x64.zip C:\\build\\node-v16.14.0-win-x64.zip
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
RUN Expand-Archive C:\build\node-v16.14.0-win-x64.zip C:\; Rename-Item C:\node-v16.14.0-win-x64 node
RUN SETX PATH C:\node
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Source/Business/OnlineIde/OnlineIde.Api/OnlineIde.Api.csproj", "Source/Business/OnlineIde/OnlineIde.Api/"]
COPY ["Source/Business/OnlineIde/OnlineIde.Application/OnlineIde.Application.csproj", "Source/Business/OnlineIde/OnlineIde.Application/"]
COPY ["Source/Infrastructure/Infrastructure.DataAccess/Infrastructure.DataAccess.csproj", "Source/Infrastructure/Infrastructure.DataAccess/"]
COPY ["Source/Infrastructure/Infrastructure.Interfaces/Infrastructure.Interfaces.csproj", "Source/Infrastructure/Infrastructure.Interfaces/"]
COPY ["Source/Infrastructure/Infrastructure.Domain/Infrastructure.Domain.csproj", "Source/Infrastructure/Infrastructure.Domain/"]
COPY ["Source/Infrastructure/Infrastructure.Core/Infrastructure.Core.csproj", "Source/Infrastructure/Infrastructure.Core/"]
COPY ["Source/Infrastructure/Infrastructure.WebApi/Infrastructure.WebApi.csproj", "Source/Infrastructure/Infrastructure.WebApi/"]
RUN dotnet restore "Source/Business/OnlineIde/OnlineIde.Api/OnlineIde.Api.csproj"
COPY . .
WORKDIR "/src/Source/Business/OnlineIde/OnlineIde.Api"
RUN dotnet build "OnlineIde.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "OnlineIde.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["dotnet", "OnlineIde.Api.dll"]
我正在使用docker build进行构建。 -t servertest 命令。然后我尝试使用 docker run --name servertest -p 5000:80 -d servertest 命令运行。节点正在运行安装。但是当我尝试访问 localhost:5000/swagger 时,它给出错误“无法访问此站点”。我需要授予防火墙权限吗?
I would like to run .net 6 api, java runtime and nodejs in same docker image. I installed java in servercore docker image, it run I expected. And I deployed .net 6 in aspnet docker image, then it worked. But I can not deploy .net 6 api and java in same servercore docker image. How can I deploy .net 6 api in server core image?
UPDATE:
FROM mcr.microsoft.com/windows/servercore:ltsc2022-amd64 as base
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
## Install .net
RUN Invoke-WebRequest -OutFile dotnet-sdk-6.0.102-win.exe https://download.visualstudio.microsoft.com/download/pr/fb14ba65-a9c9-49ce-9106-d0388b35ae1b/7bbfe92fb68e0c9330c9106b5c55869d/dotnet-sdk-6.0.102-win-x64.exe; \
Start-Process "dotnet-sdk-6.0.102-win.exe" -ArgumentList "/passive" -wait -Passthru; \
Remove-Item -Force dotnet-sdk-6.0.102-win.exe
## Install Node
ADD https://nodejs.org/dist/v16.14.0/node-v16.14.0-win-x64.zip C:\\build\\node-v16.14.0-win-x64.zip
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
RUN Expand-Archive C:\build\node-v16.14.0-win-x64.zip C:\; Rename-Item C:\node-v16.14.0-win-x64 node
RUN SETX PATH C:\node
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Source/Business/OnlineIde/OnlineIde.Api/OnlineIde.Api.csproj", "Source/Business/OnlineIde/OnlineIde.Api/"]
COPY ["Source/Business/OnlineIde/OnlineIde.Application/OnlineIde.Application.csproj", "Source/Business/OnlineIde/OnlineIde.Application/"]
COPY ["Source/Infrastructure/Infrastructure.DataAccess/Infrastructure.DataAccess.csproj", "Source/Infrastructure/Infrastructure.DataAccess/"]
COPY ["Source/Infrastructure/Infrastructure.Interfaces/Infrastructure.Interfaces.csproj", "Source/Infrastructure/Infrastructure.Interfaces/"]
COPY ["Source/Infrastructure/Infrastructure.Domain/Infrastructure.Domain.csproj", "Source/Infrastructure/Infrastructure.Domain/"]
COPY ["Source/Infrastructure/Infrastructure.Core/Infrastructure.Core.csproj", "Source/Infrastructure/Infrastructure.Core/"]
COPY ["Source/Infrastructure/Infrastructure.WebApi/Infrastructure.WebApi.csproj", "Source/Infrastructure/Infrastructure.WebApi/"]
RUN dotnet restore "Source/Business/OnlineIde/OnlineIde.Api/OnlineIde.Api.csproj"
COPY . .
WORKDIR "/src/Source/Business/OnlineIde/OnlineIde.Api"
RUN dotnet build "OnlineIde.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "OnlineIde.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["dotnet", "OnlineIde.Api.dll"]
I am building with the docker build . -t servertest
command. Then I am trying to run with the docker run --name servertest -p 5000:80 -d servertest
command. Node is running installed. But when I try to go to localhost:5000/swagger it gives error 'This site can't be reached'. Do I need to grant firewall permission?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论