Docker build command hangs

I’m trying to build a minimal image to allow compilation in Windows via the Visual Studio build tools. (basically, Install Visual Studio Build Tools into a container to support a consistent build system | Microsoft Learn)

I’ve been working through various issues, but seem to be blocked now. I’ve a feeling the the Docker cache has gotten into a bad state, but the --no-cache option doesn’t seem to help.

Script at end.

docker build --no-cache -t vs/buildtools:latest -m 16GB .

Gets the following in the log, and then hangs. I have to press ctrl-c to exit

 ---> Running in f2c6fdde6ad4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 3863k  100 3863k    0     0  6500k      0 --:--:-- --:--:-- --:--:-- 6500k

The same thing happens if I comment in the second curl command in the script. Or the normal script after I ran with --no-cache.


# escape=`

# Use the latest Windows Server Core 2022 image.

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

    # Download the Build Tools bootstrapper.
    curl -SL --output vs_buildtools.exe `
    # Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
    && (start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
        --installPath "%ProgramFiles%\Microsoft Visual Studio\2022\BuildTools" `
        --add Microsoft.VisualStudio.Component.TestTools.BuildTools `
		--add Microsoft.VisualStudio.Component.VC.CMake.Project `
		--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `		
		--add Microsoft.Net.Component.4.8.SDK `
		--add Microsoft.VisualStudio.Component.VC.ATL `
		--add Microsoft.VisualStudio.Component.VC.ATLMFC `
		--add Microsoft.VisualStudio.Component.VC.CLI.Support `
		--add Microsoft.VisualStudio.Component.VC.Llvm.Clang `
		--add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset `
		--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Llvm.Clang `
		--remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
		--remove Microsoft.VisualStudio.Component.Windows10SDK.15063 `
		--remove Microsoft.VisualStudio.Component.Windows10SDK.16299 `
		--remove Microsoft.VisualStudio.Component.Windows10SDK.17134 `
		--add Microsoft.VisualStudio.Component.Windows11SDK.22621 `		
        || IF "%ERRORLEVEL%"=="3010" EXIT 0) `
    # Cleanup
    && del /q vs_buildtools.exe `	
	# Install nuget
	# curl -SL --output nuget.exe `
	# Install git for windows
	# && nuget install Git-Windows-Minimal -Version 2.43.0

# This should be the default user for servercore but not nanoserver
# USER ContainerAdministrator

# Define the entry point for the docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
# ENTRYPOINT ["C:\\Program Files\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "-arch=amd64"]

Have you tried to just run a container from the base image and execute the commands you have in the Dockerfile?

Yes - they all work.

What does seem to work is to delete the local servercore image and redownload it every time. Works with the second curl and nuget install lines added too.


I don’t know what it could be caused by. If it works only when you delete the image, that’s as if downlading the image activated the network and curl could work, which doesn’t make sense to me.

Not a solution, just an idea for debugging, but I would try to add some delay before running curl.

…and now even that workaround fails. A machine reboot and a re-install later, the build does the same, then Docker Desktop crashed.

I had a working image creation script - I just added my username to the tag in the command line so I could upload to Docker Hub, and it hasn’t worked since.

Diagnostic zip uploaded.