2

I am using ASP.NET Core 3 with Angular and Docker Windows Container.

I followed as below:

https://learn.microsoft.com/en-us/visualstudio/containers/container-tools-react?view=vs-2019#modify-the-dockerfile-windows-containers

I have created docker compose and docker file

Dockerfile

# escape=`
FROM mcr.microsoft.com/powershell:nanoserver-1903 AS downloadnodejs
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
RUN Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v10.16.3/node-v10.16.3-win-x64.zip"; `
Expand-Archive nodejs.zip -DestinationPath C:\; `
Rename-Item "C:\node-v10.16.3-win-x64" c:\nodejs

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 80
COPY --from=downloadnodejs C:\nodejs\ C:\Windows\system32\

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1903 AS build
COPY --from=downloadnodejs C:\nodejs\ C:\Windows\system32\
WORKDIR /src
COPY ["HardwareResources/HardwareResources.csproj", "HardwareResources/"]
RUN dotnet restore "HardwareResources/HardwareResources.csproj"
COPY . .
WORKDIR "/src/HardwareResources"
RUN dotnet build "HardwareResources.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "HardwareResources.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HardwareResources.dll"]

Docker-compose.yml

version: '3.4'

services:
  hardwareresources:
    image: ${DOCKER_REGISTRY-}hardwareresources
    build:
      context: .
      dockerfile: HardwareResources\Dockerfile

I run Docker compose in VS2019 and I am getting error pop up message and it says:

enter image description here

Could you please advise how to resolve this issue?

Dale K
  • 25,246
  • 15
  • 42
  • 71

1 Answers1

0

for aspnet:5.0 below Docker configuration for windows container worked for me

# escape=`

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN curl.exe -o node.zip https://nodejs.org/dist/v10.16.3/node-v10.16.3-win-x64.zip && `
  mkdir "C:\\node" && `
  tar.exe -xf node.zip -C "C:\\node" --strip-components=1
RUN setx path "%path%;C:\node"

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
RUN curl.exe -o node.zip https://nodejs.org/dist/v10.16.3/node-v10.16.3-win-x64.zip && `
  mkdir "C:\\node" && `
  tar.exe -xf node.zip -C "C:\\node" --strip-components=1
RUN setx path "%path%;C:\node"
WORKDIR /src
COPY ["Spa/Spa.csproj", "Spa/"]
RUN dotnet restore "Spa/Spa.csproj"
COPY . .
WORKDIR "/src/Spa"
RUN dotnet build "Spa.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Spa.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Spa.dll"]

In summary the changes were

  • using curl instead of powershell
  • not copying to system32.
  • after downloading node to c:\node, setting the windows correct PATH.
surya
  • 1,351
  • 1
  • 13
  • 29