dockerwindows-server-2019

Install Docker Windows Server 2019: the term 'docker' is not recognized as the name of a cmdlet, function, script file, or operable program


Trying to install Docker in process isolation on Windows Server 2019 and following these steps. (I can't use Hyper-V on this server) when running PowerShell in admin mode.

I however get the error

Get-PackageProvider : A parameter cannot be found that matches parameter name 'ListAvailableget-packagesource' enter image description here

I also tried Install-Package -Name docker -ProviderName DockerMsftProvider I then get:

Install-Package : Unable to find package providers (DockerMsftProvider).
At line:1 char:1
+ Install-Package -Name docker -ProviderName DockerMsftProvider
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
   xception
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Install-Package : Unable to find package providers (DockerMsftProvider).
At line:3 char:1
+ Install-Package -Name docker -ProviderName DockerMsftProvider
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
   xception
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

UPDATE 1

I had to set the PowerShell execution policy to unrestricted like so (I'll set it back to Restricted Set-ExecutionPolicy -ExecutionPolicy Restricted after all this):

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

I also had to temporarily disable some antivirus/malware protection from Windows Defender. For me antimalware was already disabled so I had to also disable real-time virus protection.

I then could run

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

Now via Get-PackageProvider -ListAvailable I see that DockerMsftProvider is installed.

Name                     Version          DynamicOptions
----                     -------          --------------
DockerMsftProvider       1.0.0.8          Update
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.208        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

I ran Install-Package -Name docker -ProviderName DockerMsftProvider and entered Y.

I then run Get-Package -Name Docker -ProviderName DockerMsftProvider and get:

Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
docker                         20.10.0          DockerDefault                    DockerMsftProvider

When I run Install-Package -Name docker -ProviderName DockerMsftProvider I get no feedback via PowerShell, no errors, so I think it's good.

However, when I checked here and ran docker run --isolation=process mcr.microsoft.com/windows/nanoserver:1809 cmd.exe /c ping 127.0.0.1 -t

I get the error

docker : The term 'docker' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ docker run --isolation=process mcr.microsoft.com/windows/nanoserver:1 ...
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (docker:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

In the past I had tried to install Docker Desktop, which I then uninstalled since my VPS does not support Hyper-V. I'm not sure if this is still from that install or new, but I added path C:\Program Files\Docker to my environment PATH variable.

enter image description here

Still I get the same error

The term 'docker' is not recognized as the name of a cmdlet, function, script file, or operable program.

UPDATE 2

Based on @Peter Wishart's answer I checked my PATH system variables, but Docker can be seen there (see screenshot below) and as Peter also mentioned, since I can run docker --version via the command prompt (not PowerShell) the install did complete successfully.

enter image description here

UPDATE 3
I checked ($env:path).Split(";") in PowerShell and the Docker path is there: enter image description here

How can I install Docker?


Solution

  • I use a script that installs the containers feature and uninstalls Windows Defender (n.b. this may or may not be safe for your environment):

    $rebootNeeded = $false
    if (-not (Get-WindowsFeature Containers).Installed) {
      $rebootNeeded = $rebootNeeded -or (Install-WindowsFeature -Name Containers).RestartNeeded
    }
    
    if ((Get-WindowsFeature Windows-Defender).Installed) {
      $rebootNeeded = $rebootNeeded -or (Uninstall-WindowsFeature Windows-Defender).RestartNeeded
    }
    
    if ($rebootNeeded) { throw "Reboot then rerun to complete docker installation" }
    
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
    Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
    Install-Package -Name docker -ProviderName DockerMsftProvider -Force
    Start-Service docker  
    docker --version
    

    I mention this in case its an option to just reset the machine if nothing else works...

    I think your first problem was a copy/paste error at the Get-PackageProvider step.

    The files you listed are the correct ones for the latest DockerEE version.

    If you run docker directly from there e.g. &"C:\Program Files\Docker\docker.exe" --version and it doesn't work, then there's an environmental problem other than the path - try reinstalling Docker.

    If you restart Powershell and run ($env:path).Split(";"), the only Docker entry should be C:\Program Files\Docker - perhaps there are some leftovers from Docker Desktop interfering?

    [Edit]

    It appears that the system path was corrupted in a subtle way (although the docker path was present and correct).

    I think if you check the path configuration carefully and/or move the docker path nearer the start of the path, you should be able to get a permanent fix.