0

DockerFile with dotnet/sdk/5 says no cmd executable in $PATH whereas with /dotnet/framework/sdk:4.8 , it works fine

Our dockerfile has .net framework 4.8 (mcr.microsoft.com/dotnet/framework/sdk:4.8) and also installs VS build tools.

This works fine.

Current requirement is to upgrade to use .net 5.0 SDK instead of 4.8 dotnet/sdk:5.0

DockerFile is as below:

#FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
 FROM mcr.microsoft.com/dotnet/sdk:5.0

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

# Download the Visual Studio Build Tools bootstrapper.
ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\Temp\vs_buildtools.exe

# Use the latest release channel.
ADD https://aka.ms/vs/16/release/channel C:\Temp\VisualStudio.chman
# Set up environment to collect install errors.
COPY Install.cmd C:\Temp\
ADD https://aka.ms/vscollect.exe C:\Temp\collect.exe

# Modify MSVC C++ compiler, CMake, and MSBuild.
RUN c:\Temp\Install.cmd C:\Temp\vs_buildtools.exe modify `
    --quiet --wait --norestart --nocache `
    --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools" `
    --channelUri C:\Temp\VisualStudio.chman `
    --installChannelUri C:\Temp\VisualStudio.chman `
    --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools;includeRecommended `
    --add Microsoft.VisualStudio.Workload.VCTools;includeRecommended `
    --add Microsoft.Component.MSBuild `
    --add Microsoft.VisualStudio.Component.VC.ATLMFC

# Start developer command prompt with any other commands specified.
WORKDIR /src
ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

Error I am getting is

container_linux.go:380: starting container process caused: exec: "cmd": executable file not found in $PATH

My Docker desktop uses WSL2 and Linux distribution installed is Ubuntu 20.04 LTS

Lakshmi
  • 81
  • 1
  • 1
  • 4
  • .NET framework is WIndows only so the Docker images for it are Windows images. The default image for .NET 5.0 is a Linux image, so there's no CMD program installed and all the commands you RUN in the Dockerfile need to be Linux commands. You can get a Windows image by specifying `FROM mcr.microsoft.com/dotnet/sdk:5.0-nanoserver-20H2` but as I read your post, it sounds like you want to move to Linux? – Hans Kilian Oct 29 '21 at 07:42
  • My primary intention is not moving to Linux but just that the I am using WSL2 as it could be more efficient. Since , my Shell is cmd as per my docker file, I get this error while it comes to the line 'RUN c:\Temp\Install.cmd C:\Temp\vs_buildtools.exe ...' . How can this be altered for Linux image ? Do you have any recommendation ? – Lakshmi Oct 29 '21 at 07:51
  • You're trying to run windows commands inside a Linux container. You either need to switch docker to run windows containers in the preferences, or switch your logic to be based on Linux containers. In my experience, everyone goes for the latter eventually. – BMitch Oct 29 '21 at 10:02
  • @BMitch - I think I understand your point. So, was the dotnet/framework/4.8 a windows image but dotnet/sdk/5 a Linux image ? can you help me in rephrasing my DockerFile logic for a Linux container ? I am new to Linux. – Lakshmi Oct 29 '21 at 11:40
  • The framework/sdk:4.8 is a multi-platform image with only windows platforms. The framework/sdk:5.0 image is also a multi-platform image, but includes both windows and linux variants. – BMitch Oct 29 '21 at 14:18

1 Answers1

0

This error occurs when Docker is in Linux containers mode. Run this command to switch:

"C:\Program Files\Docker\Docker\dockercli" -switch

The other way is to find Docker in tray and select Switch to Windows containers

Codeguard
  • 7,787
  • 2
  • 38
  • 41