Docker API应用程序,在 ASP.Net 从Visual Studio Only成功构建,而不是从git-bas



来自 IDE 的 Docker 构建命令:

12>docker build -f "D:sampleprojectSrcServicesExampleExample.APIDockerfile" --force-rm -t exampleapi:dev --target base  --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=Example.API" "D:sampleproject"

来自 IDE 的 Docker 运行命令:

12>docker run -dt -v "C:Usersjohndvsdbgvs2017u5:/remote_debugger:rw" -v "D:sampleprojectSrcServicesExampleExample.API:/app" -v "D:sampleproject:/src/" -v "C:UsersjohndAppDataRoamingMicrosoftUserSecrets:/root/.microsoft/usersecrets:ro" -v "C:UsersjohndAppDataRoamingASP.NETHttps:/root/.aspnet/https:ro" -v "C:Usersjohnd.nugetpackages:/root/.nuget/fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages" -P --name Example.API --entrypoint tail exampleapi:dev -f /dev/null

从命令提示符生成和运行,使容器保持运行状态。终结点不可访问。例如,curlhttp://localhost:32823/swagger/index.html从服务器返回空回复。

docker build -f dockerfile-example --force-rm -t contentocr.azurecr.io/exampleapi:lore --label "com.content.created-by=git-bash" .
docker run -dt  -v "C:Usersjohnd.nugetpackages:/root/.nuget/fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages" -P --name Example.API --entrypoint tail contentocr.azurecr.io/exampleapi:lore -f /dev/null

从容器内部,curl http://localhost:80/swagger/index.html返回连接被拒绝错误消息文本。

码头工人文件如下

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["Src/Services/Example/Example.API/Example.API.csproj", "Src/Services/Example/Example.API/"]
COPY ["Src/Dependencies/Dependency/Dependent.csproj", "Src/Dependencies/Dependency/"]
RUN dotnet restore "Src/Services/Example/Example.API/Example.API.csproj"
RUN dotnet restore "Src/Dependencies/Dependency/Dependent.csproj"
COPY . .
WORKDIR "/src/Src/Services/Example/Example.API"
RUN dotnet build "Example.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Example.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY devops/SSL/UserSecrets /root/.microsoft/usersecrets
COPY devops/SSL/ASP.NET/Https/Example.API.tmpcert /root/.aspnet/https/Example.API.pfx
ENV ASPNETCORE_ENVIRONMENT="Development"
ENV ASPNETCORE_URLS=https://+:443;http://+:80
ENTRYPOINT ["dotnet", "Example.API.dll"]

如何从git-bash/power/cmdshell 构建和执行容器?

对 docker 文件进行更新以包含 Visual Studio 卷装载可解决此问题,如下所示: 第 #Volume 节挂载显式复制 --

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["Src/Services/Example/Example.API/Example.API.csproj", "Src/Services/Example/Example.API/"]
COPY ["Src/Dependencies/Dependency/Dependent.csproj", "Src/Dependencies/Dependency/"]
RUN dotnet restore "Src/Services/Example/Example.API/Example.API.csproj"
RUN dotnet restore "Src/Dependencies/Dependency/Dependent.csproj"
COPY . .
WORKDIR "/src/Src/Services/Example/Example.API"
RUN dotnet build "Example.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Example.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
#Volume mount explicit copy
#COPY /c/Users/johnd/vsdbg/vs2017u5 /remote_debugger 
COPY ./Src/Services/Example/Example.API /app
COPY . /src/
COPY ./devops/SSL/UserSecrets /root/.microsoft/usersecrets
COPY ./devops/SSL/ASP.NET/Https/Example.API.tmpcert /root/.aspnet/https/Example.API.pfx
#COPY C:\Users\johnd\.nuget\packages\ /root/.nuget/fallbackpackages 
ENV DOTNET_USE_POLLING_FILE_WATCHER=1 
ENV ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true 
ENV ASPNETCORE_ENVIRONMENT=Development 
ENV ASPNETCORE_URLS=https://+:443;http://+:80 
ENV NUGET_PACKAGES=/root/.nuget/fallbackpackages 
ENV NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.API.dll"]

最新更新