I am trying to follow sitecore 10 example in docker (https://containers.doc.sitecore.com/docs/build-solution) and as an out of box step worked correctly, I am having issue on step 6 with build solution. Every time resulting with an error below:

PS K:\docker-examples\custom-images> docker-compose build solution
Building solution
Step 1/21 : ARG BASE_IMAGE
Step 3/21 : FROM ${BUILD_IMAGE} AS prep
 ---> a1f61ee40a8e
Step 4/21 : COPY *.sln nuget.config Directory.Build.targets Packages.props \nuget\
 ---> Using cache
 ---> 2ad252c633e3
Step 5/21 : COPY src\ \temp\
 ---> Using cache
 ---> a2855d9bc5d3
Step 6/21 : RUN Invoke-Expression 'robocopy C:\temp C:\nuget\src /s /ndl /njh /njs *.csproj *.scproj packages.config'
 ---> Running in c911b9d4e67d
'Invoke-Expression' is not recognized as an internal or external command,
operable program or batch file.
ERROR: Service 'solution' failed to build : The command 'cmd /S /C Invoke-Expression 'robocopy C:\temp C:\nuget\src /s /ndl /njh /njs *.csproj *.scproj packages.config'' returned a non-zero code: 1

Powershell version: 5.1.19041.610, Windows version: 20H2

Update: Docker file added

    # escape=`



# Gather only artifacts necessary for NuGet restore, retaining directory structure
COPY *.sln nuget.config Directory.Build.targets Packages.props \nuget\
COPY src\ \temp\

RUN Invoke-Expression 'robocopy C:\temp C:\nuget\src /s /ndl /njh /njs *.csproj *.scproj packages.config'



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

# Create an empty working directory
WORKDIR C:\build

# Copy prepped NuGet artifacts, and restore as distinct layer to take better advantage of caching
COPY --from=prep .\nuget .\
RUN nuget restore

# Copy remaining source code
COPY src\ .\src\

# Copy transforms, retaining directory structure
RUN Invoke-Expression 'robocopy C:\build\src C:\out\transforms /s /ndl /njh /njs *.xdt'

# Build website with file publish
RUN msbuild .\src\DockerExamples.Website\DockerExamples.Website.csproj /p:Configuration=$env:BUILD_CONFIGURATION /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:PublishUrl=C:\out\website

# Build XConnect with file publish
RUN msbuild .\src\DockerExamples.XConnect\DockerExamples.XConnect.csproj /p:Configuration=$env:BUILD_CONFIGURATION /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:PublishUrl=C:\out\xconnect


WORKDIR C:\artifacts

# Copy final build artifacts
COPY --from=builder C:\out\website .\website\
COPY --from=builder C:\out\transforms .\transforms\
COPY --from=builder C:\out\xconnect .\xconnect\
  • Please share the dockerfile Dec 1, 2020 at 20:39
  • I have checked this on two machines with same windows version and it fails on both. Seems like Windows version 2004 works correctly on one of my work colleague laptop, and the windows version seems to be only difference.
    – Kamil C
    Dec 2, 2020 at 10:24

2 Answers 2


The solution for this issue was to add

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

before first RUN Invoke-Expression

Update: Seems like 20H2 defaults to CMD instead of SHELL.

  • This worked perfectly for me. I had to put this line in front of every 'Invoke-Expression' though, in this case also before the second call to robocopy.
    – Markus
    Dec 6, 2020 at 12:37
  • Had this issue as well, and shouldn't be an issue for anyone with a different OS build version. Apr 6, 2021 at 15:08

I've stepped into the same behavior on the same Windows 10, 20H2 update; a friend of mine has no issue on a prev. Windows update as well.

The log message has a clue: ...The command 'cmd /S /C Invoke-Expression..

Dockerfile builder somehow defaults to CMD over Powershell; therefore we need to enforce SHELL to use Powershell.

Looking at the question from a bit different angle: Invoke-Expression is considered to be removed from Powershell; you could use instead:

RUN ("robocopy", "a", "b", "option1", "option2")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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