Build pipeline on Azure VM - powershell command inside dockerfile hangs

Expected behavior

The build pipeline based on ,NET Framework 4.8 should build the solution

Actual behavior

Docker builds hangs with the following command:

RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path ."

And eventually times out with the following error message:

Step 6/9 : RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path ."

[45](https://esw-github.33858.volvo.net/Volvo-Open-Development-Community/V5FrameworkDiagnostics/actions/runs/139776/job/366115#step:7:46)container afc6565e10d642d894b952bd1ce14c3456db59b06e082eec67a441cbc617c509 encountered an error during hcs::System::Start: context deadline exceeded

Additional Information

Steps to reproduce the behavior from the dockerfile contents

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
ARG PACKAGE_VERSION
WORKDIR /V5FrameworkDiagnosticsBuild
COPY . ./
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path ."

It have been several days since it has been posted and yet no response. I guess you need more information to address this issue. These commands are from the dockerfile running from an Azure Windows VM (Windows Server 2022) . The docker installation is has the docker server version 27.1.1.

The reason of why you didn’T get any answer is probably that we can’t answer. It is good that you came back providing more information as that often helps, but in this case I have no idea how that powershell app should work and what it rquires to run. The issue would require someone with better Windows skills and most of us (meaning active community members) work with Linux. Even on Linux just knowing the fact that an application hangs, doesn’t really help much. Knowing the app itself or the sourcode in case of open source software helps more.

What I can say is that not all applications can run in containers. Or at least not without the right permissions. ON Linux, you would use Linux kernel capabilities, but I have no idea what Windows would require. It is also important that Windows containers don’t support GUI applications. So if the app requires a GUI, that won’t run.

You could try to ask about it on a Microsoft forum. Or you can also search for the error message and find issues like this:

I haven’t read it, but hopefully it could point you to the right direction.

What is the expected result you have on this? Running “Get-ChildItem -Path .” is like running a “dir” command in CMD.

PS C:\Users\vinicius> Get-ChildItem -Path .


    Directory: C:\Users\vinicius


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----          8/2/2024   8:07 AM                .Azure
d-----         3/24/2022  11:15 AM                .azure-kubectl
d-----          3/2/2022   2:16 PM                .azurefunctions
d-----          4/3/2023  11:26 AM                .docfx
d-----          8/5/2024   8:53 AM                .docker
d-----         7/29/2024   1:24 PM                .dotnet
d-----         3/24/2022  11:24 AM                .kube
d-----         1/23/2024   2:46 PM                .minikube
d-----         6/27/2022  10:34 AM                .ms-ad
d-----          3/2/2022   2:18 PM                .nuget
d-----          3/2/2022   2:18 PM                .omnisharp
d-----         3/24/2022   2:33 PM                .redhat
d-----         6/19/2024   2:32 PM                .ssh
d-----          3/2/2022   7:59 AM                .vs-kubernetes
d-----         6/12/2023   2:39 PM                .vscode
d-r---         1/26/2022   2:55 PM                3D Objects
d-r---        10/17/2022   6:04 PM                Contacts
d-----         5/22/2024   4:18 PM                Docs Authoring
d-----         1/26/2022   3:00 PM                Documents
d-r---         7/30/2024  11:52 AM                Downloads
d-r---         1/13/2023   5:04 AM                Favorites
d-r---         1/13/2023   5:04 AM                Links
d-r---          8/5/2024   8:52 AM                Microsoft
d-r---         1/18/2023   1:34 PM                Music
dar--l          8/5/2024   8:52 AM                OneDrive
dar--l          8/5/2024   8:52 AM                OneDrive - Microsoft
d-r---         1/13/2023   5:04 AM                Saved Games
d-r---         1/13/2023   5:04 AM                Searches
d-----          2/3/2022   8:17 PM                Tracing
d-r---         1/13/2023   3:23 PM                Videos
-a----         6/10/2022   9:24 AM              2 --help
-a----         7/31/2024   3:52 PM            627 .gitconfig
-a----         4/18/2023  12:45 PM       33367824 AzureCLI.msi
-a----          3/7/2024   8:53 AM           5196 conn.rdp
-a----         2/12/2024   9:15 AM          38664 msilog.log
-a----         2/12/2024   9:14 AM        2129920 sqlcmdx64.msi

yes, this is where it is stuck, there are several other RUN command following this - RUN powershell -NoProfile -ExecutionPolicy Bypass -Command “Get-ChildItem -Path .”.

As a best practice, you should try to combine as many RUN/PowerShell commands into a single one. The reason is the image will get larger since each RUN command is a new layer added to your image. The other thing is, since each image is a new container being run and executing a command, you might miss shell context from one session to the next.
My recommendation is that you either combine the RUN commands into a single one, like this:

#escape=`

FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2022
RUN powershell -command `
    Add-WindowsFeature Web-CertProvider; `
    Add-WindowsFeature Web-Asp-Net45 -includeallsubfeature; `
    Add-WindowsFeature Web-Asp-Net -includeallsubfeature

(Note: The formatting here in the forum is breaking the formatting of the dockerfile example above)

The other alternative, is to add all your commands into a .ps1 PowerShell script file, use COPY to copy the file in the dockerfile, then run the script file inside the container. Each alternative has its pros and cons and you need to see for your environment what is the best approach. Also, it might help solve the issue you are seeing.

I fixed it. Just make sure you use the code block instead of the quote button as mentioned in our formatting guide. Sometimes it requires clicking on the gear icon

1 Like