6

Please, observe:

C:\> docker run -it mcr.microsoft.com/powershell pwsh
PowerShell 6.2.4
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /> Get-PSRepository
WARNING: Unable to find module repositories.
PS /> Get-PackageProvider

Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipVali…
PowerShellGet            2.1.3.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Fil…

PS /> Register-PSRepository -Default
PS /> Get-PSRepository
WARNING: Unable to find module repositories.
PS /> $env:PSModulePath
/root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/6/Modules
PS />

So, there is no PS repositories. OK, I run Register-PSRepository -Default - it does not fail. But it also does nothing - I still have no PS repositories.

Other people have the same issue, but I did not understand how they resolved it. What blows my mind is that it is microsoft's powershell image that does not work.

What am I missing?

EDIT 1

Please, allow me to clarify the acceptance criteria for an answer. If your answer shows how one can run docker run -it mcr.microsoft.com/powershell pwsh and then Get-PSRepository - you hit the mark and get the points.

mark
  • 59,016
  • 79
  • 296
  • 580
  • 1
    I have the same problem. If I disconnect from my VPN, and I run `Register-PSRepository` it performs as expected. It is only on the VPN that it fails. I suspect the issue is that it has to reach.. Something (www.powershellgallery.com?) in order to successfully register the repository. It looks like this after execution: ```Get-PSRepository Name InstallationPolicy SourceLocation ---- ------------------ -------------- PSGallery Untrusted https://www.powershellgallery.com/api/v2 ``` – Doug Moore Mar 01 '21 at 16:56
  • I did not have any issues in my environment, even being on VPN (although I'm not using Cisco AnyConnect as some having issues seem to be). Does name resolution work? You can test with `[System.Net.Dns]::GetHostAddresses('www.powershellgallery.com')` – briantist Mar 02 '21 at 17:57

4 Answers4

3

The answer for me seems to be to run this after I connect to VPN

Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)" | Set-NetIPInterface -InterfaceMetric 1
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000

I found this at https://sysblog.dk/?p=254

If you would like to "set it and forget it", follow these instructions for setting up a scheduled task trigger.

Doug Moore
  • 1,173
  • 9
  • 23
  • I thought this was the fix, but now I am having the problem again. This is incredibly frustrating, but I think it still confirms that VPN is the issue. – Doug Moore Mar 02 '21 at 20:10
  • I have additional security features that are getting in the way, but once I get around those, this is still a valid fix. – Doug Moore Mar 03 '21 at 11:28
0

I ran into the same problem, the issue was that the container was connected to the internet but not were not finding the DNS address. If you run ping google.com and does not work you have a similar problem.

The fix is to set "dns": ["1.1.1.1"] in the Docker JSON configuration file as described here: Not able to access internet inside docker windows container

Erick Guillen
  • 547
  • 4
  • 11
0

I don't think in Linux this is the point because:

$ docker run -it mcr.microsoft.com/powershell bash
root@a92d3c657304:/# apt -qq update; apt install -qq -y iputils-ping
root@a92d3c657304:/# ping www.google.com
PING www.google.com (216.58.215.228) 56(84) bytes of data.
64 bytes from zrh11s02-in-f4.1e100.net (216.58.215.228): icmp_seq=1 ttl=111 time=6.01 ms
64 bytes from zrh11s02-in-f4.1e100.net (216.58.215.228): icmp_seq=2 ttl=111 time=6.04 ms
64 bytes from zrh11s02-in-f4.1e100.net (216.58.215.228): icmp_seq=3 ttl=111 time=5.49 ms
learning-man
  • 119
  • 2
  • 11
0

For me, the answer was very simply: disconnect from the VPN, then run Register-PSRepository -Default inside the container.

sfuqua
  • 5,797
  • 1
  • 32
  • 33