mark
mark

Reputation: 62712

How to install powershell modules within a docker container off the mcr.microsoft.com/powershell image?

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.

Upvotes: 6

Views: 1669

Answers (4)

sfuqua
sfuqua

Reputation: 5853

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

Upvotes: 0

Doug Moore
Doug Moore

Reputation: 1193

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.

Upvotes: 3

learning-man
learning-man

Reputation: 169

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

Upvotes: 0

Erick Guillen
Erick Guillen

Reputation: 595

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

Upvotes: 0

Related Questions