4

TLDR I am getting '$path' is not recognized as an internal or external command, when running up.ps1 in step 7 of Create the MyProject solution in the Sitecore 10 Getting Started Template.

The bit of code in question is in docker/build/dotnetsdk/dockerfile

# escape=`

# This is a custom SDK image based on servercore that serves two purposes:
#   * Allows us to build a mixed solution (framework and netcore)
#   * Allows us to run `dotnet watch` for rendering host development
#     (see https://github.com/dotnet/dotnet-docker/issues/1984)

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as netcore-sdk
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8

# Ensure updated nuget. Depending on your Windows version, dotnet/framework/sdk:4.8 tag may provide an outdated client.
# See https://github.com/microsoft/dotnet-framework-docker/blob/1c3dd6638c6b827b81ffb13386b924f6dcdee533/4.8/sdk/windowsservercore-ltsc2019/Dockerfile#L7
# ENV NUGET_VERSION 5.8.0
# RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v$env:NUGET_VERSION/nuget.exe" -UseBasicParsing -OutFile "$env:ProgramFiles\NuGet\nuget.exe"

# Retrieve .NET Core SDK
COPY --from=netcore-sdk ["/Program Files/dotnet/", "/Program Files/dotnet/"]

ENV `
    # Enable detection of running in a container
    DOTNET_RUNNING_IN_CONTAINER=true `
    # Enable correct mode for dotnet watch (only mode supported in a container)
    DOTNET_USE_POLLING_FILE_WATCHER=true `
    # Skip extraction of XML docs - generally not useful within an image/container - helps performance
    NUGET_XMLDOC_MODE=skip 

RUN $path = ${Env:PATH} + ';C:\Program Files\dotnet\;'; `
    setx /M PATH $path

# Trigger first run experience by running arbitrary cmd
RUN dotnet help | out-null

Any idea what I'm doing wrong?

Env

  • Powershell running in admin, version 5.1.19041.610
  • .Net Framework version 4.8.04084
  • .Net core version 5.0.102
  • Docker Desktop 3.1.0 (51484) with docker for windows enabled
  • VS 2019 community

Output

.\up.ps1
Building containers...
traefik uses an image, skipping
Building solr
Step 1/2 : ARG PARENT_IMAGE
Step 2/2 : FROM ${PARENT_IMAGE}
 ---> 81bd20568e21

Successfully built 81bd20568e21
Successfully tagged myproject-xp0-solr:latest
Building mssql
Step 1/7 : ARG PARENT_IMAGE
Step 2/7 : ARG HEADLESS_SERVICES_IMAGE
Step 3/7 : FROM ${HEADLESS_SERVICES_IMAGE} AS headless_services
 ---> 2da0dc9f1eaf

Step 4/7 : FROM ${PARENT_IMAGE}
 ---> 6eb6bf976fcd
Step 5/7 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
 ---> Using cache
 ---> f7101fc97967
Step 6/7 : COPY --from=headless_services C:\module\db C:\jss_data
 ---> Using cache
 ---> 4cac56a801cd
Step 7/7 : RUN C:\DeployDatabases.ps1 -ResourcesDirectory C:\jss_data;     Remove-Item -Path C:\jss_data -Recurse -Force;
 ---> Using cache
 ---> 6664ceb0ccfa

Successfully built 6664ceb0ccfa
Successfully tagged myproject-xp0-mssql:latest
Building xconnect
Step 1/2 : ARG PARENT_IMAGE
Step 2/2 : FROM ${PARENT_IMAGE}
 ---> 19d4466b0aed

Successfully built 19d4466b0aed
Successfully tagged myproject-xp0-xconnect:latest
Building xdbautomationworker
Step 1/2 : ARG PARENT_IMAGE
Step 2/2 : FROM ${PARENT_IMAGE}
 ---> d65d7ab7640f

Successfully built d65d7ab7640f
Successfully tagged myproject-xp0-xdbautomationworker:latest
Building dotnetsdk
Step 1/6 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as netcore-sdk
 ---> e82f832fabb2

Step 2/6 : FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
 ---> af16f980b5a4
Step 3/6 : COPY --from=netcore-sdk ["/Program Files/dotnet/", "/Program Files/dotnet/"]
 ---> 1beb0b042fe0
Step 4/6 : ENV     DOTNET_RUNNING_IN_CONTAINER=true     DOTNET_USE_POLLING_FILE_WATCHER=true     NUGET_XMLDOC_MODE=skip
 ---> Running in 172be5fe0676
Removing intermediate container 172be5fe0676
 ---> 039e64f7cf23
Step 5/6 : RUN $path = ${Env:PATH} + ';C:\Program Files\dotnet\;';     setx /M PATH $path
 ---> Running in 92c76af86598
'$path' is not recognized as an internal or external command,
operable program or batch file.
ERROR: Service 'dotnetsdk' failed to build : The command 'cmd /S /C $path = ${Env:PATH} + ';C:\Program Files\dotnet\;';     setx /M PATH $path' returned a non-zero code: 1
C:\dev\ScGettingStarted\MyProject\up.ps1 : Container build failed, see errors above.
At line:1 char:1
+ .\up.ps1
+ ~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,up.ps1

Note

On a fresh install I was originally getting Invoke-WebRequest is not recognized as an internal or external command - but because I already had the correct nuget, I commented this line out.

Original error

Step 4/8 : RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v$env:NUGET_VERSION/nuget.exe" -UseBasicParsing -OutFile "$env:ProgramFiles\NuGet\nuget.exe"
 ---> Running in 09e5746490a3
'Invoke-WebRequest' is not recognized as an internal or external command,
operable program or batch file.
ERROR: Service 'dotnetsdk' failed to build : The command 'cmd /S /C Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v$env:NUGET_VERSION/nuget.exe" -UseBasicParsing -OutFile "$env:ProgramFiles\NuGet\nuget.exe"' returned a non-zero code: 1
3

I think your scripts are defaulting to use basic CMD as it's shell rather than what you expect; a powershell.

Add the following to your relevant docker files.

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.