I'm installing dbatools to run on a Ubuntu Container.
Error:
Could not import /usr/local/share/powershell/Modules/dbatools/1.1.142/bin/smo/coreclr/System.Security.SecureString.dll : Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'System.Security.SecureString, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'."
At /usr/local/share/powershell/Modules/dbatools/1.1.142/internal/scripts/libraryimport.ps1:150 char:21
+ [Reflection.Assembly]::LoadFrom($assemblyPath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException
Import-Module : The specified module '/usr/local/share/powershell/Modules/dbatools/1.1.142/bin/dbatools.dll' was not loaded because no valid module file was found in any module directory.
At /Test5.ps1:12 char:1
+ Import-Module dbatools
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (/usr/local/share/po\u202642/bin/dbatools.dll:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
My Dockerfile
From myImage
RUN pwsh -Command 'Set-PSRepository -Name PSGallery -InstallationPolicy Trusted'
RUN pwsh -command "Install-Module sqlserver -Scope AllUsers -Force"
RUN pwsh -command "Install-Module dbatools -Scope AllUsers -Force"
RUN pwsh -command "Get-module -ListAvailable -Name 'dbatools'"
RUN pwsh -command "Get-module -ListAvailable -Name 'sqlserver'"
COPY Test5.ps1 .
CMD [ "pwsh", "Test5.ps1"]
myImage contains the requred setup to run powershell on ubuntu 20.
Test5.ps1
Import-Module dbatools
What do I need to do to make my powershell module work without needing to be manually imported?
THANKS!
dbatools raise this as an issue and to be fix on 2.0.
Related
I have been trying to install Chocolatey on a windows container and I get the below DownloadString exception.
Tried with RUN powershell -Command [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 to add Tls12 explicitly. Tried FROM mcr.microsoft.com/windows:20H2 and FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 base images and I get the same error.
Dockerfile
ROM mcr.microsoft.com/windows/servercore:ltsc2019
USER ContainerAdministrator
RUN powershell -Command [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
RUN powershell -Command Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Exception I am getting -
Exception calling "DownloadString" with "1" argument(s): "The underlying
connection was closed: An unexpected error occurred on a send."
At line:1 char:166
+ ... -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Host OS - Windows 10 Enterprise x64 v10.0.19044 Build 19044
Hyper-V Manager - v10.0.19041.1
Im new to docker and windows containers. Deploying on-premise solution on windows server 2016
go through this instruction and stuck on Install-Package Docker -ProviderName DockerMsftProvider -Force
WARNING: Cannot find path
'C:\Users\ADM_AG~1\AppData\Local\Temp\DockerMsftProvider\DockerDefault_DockerSearchIndex.json' because it does not
exist.
WARNING: Cannot bind argument to parameter 'downloadURL' because it is an empty string.
WARNING: The property 'AbsoluteUri' cannot be found on this object. Verify that the property exists.
WARNING: The property 'RequestMessage' cannot be found on this object. Verify that the property exists.
Install-Package : No match was found for the specified search criteria and package name 'Docker'. Try Get-PackageSour
to see all available registered package sources.
At line:1 char:1
Install-Package Docker -ProviderName DockerMsftProvider -Force
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
ception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
BUT somehow i've installed Docker
get-service docker
Status Name DisplayName
Stopped docker Docker Engine
start-service docker
start-service : Failed to start service 'Docker Engine (docker)'.
At line:1 char:1
start-service docker
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException
+ FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand
docker version
Client:
Version: 1.12.0-dev
API version: 1.24
Go version: go1.5.3
Git commit: 8e92415
Built: Thu May 26 17:08:34 2016
OS/Arch: windows/amd64
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version: open //./pipe/docker_engine: The system cannot find the file specified.
and now I can't download containers and launch Docker
docker images
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/images/json: open //./pipe/docker_engine: The system cannot find the file specified.
docker pull mcr.microsoft.com/windows/nanoserver:1809
An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/images/create?fromImage=mcr.microsoft.com%2Fwindows%2Fnanoserver&tag=1809: open //./pipe/docker_engine: The system cannot fin
d the file specified.
Containers in WindowsFeauture are enabled, TLS 1.2 is enabled, execution policy is not restricted
may it something related what dockerdefault and container image gallery are not trusted? if yes, how to set it are Trusted?
get-packagesource
Name ProviderName IsTrusted Location
test NuGet False https://www.nuget.org/api/v2
PSGallery PowerShellGet True https://www.powershellgallery.com/api/v2
ContainerImageGallery ContainerImage False http://go.microsoft.com/fwlink/?LinkID=746630&clcid=0x409
DockerDefault DockerMsftPro... False https://go.microsoft.com/fwlink/?LinkID=825636&clcid=0x409
If I were you I would:
Start over by removing docker with:
Option 1 method:
docker ps --quiet | ForEach-Object {docker stop $_}
docker system prune --volumes --all
Uninstall-Package -Name docker -ProviderName DockerMsftProvider
Uninstall-Module -Name DockerMsftProvider
Get-HNSNetwork | Remove-HNSNetwork
Remove-Item "C:\ProgramData\Docker" -Recurse
Option 2, the brute force method:
Stop-Service docker
dockerd --unregister-service
Remove-Item "C:\ProgramData\Docker" -Recurse
Remove-Item "C:\Program Files\Docker" -Recurse
And reboot to a clean system.
Install the Docker Engine from scratch:
# Install Containers feature
Install-WindowsFeature Containers
# RESTART THE SERVER!!!
# Install Docker Module
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
# Install Docker
Install-Package -Name Docker -ProviderName DockerMsftProvider -Force -Confirm:$false
# Start Docker Engine
Start-Service Docker
You should now have a working Docker installation.
Test the docker engine with the commands:
docker version
docker info
If you are still having issues executing the test commands above:
Make sure your Windows Firewall is turned off to make sure there is nothing in the way.
Also, make sure the "World Wide Web Publishing Service" is stopped just in case (at least for now).
Update the "PowerShellGet" module with
Install-Module -Name PowerShellGet -RequiredVersion 2.2.5 -Force
Let me know if it finally works.
FYI:
Container tags with "1809" are for Windows 2019. So:
mcr.microsoft.com/windows/nanoserver:1809 ==> Windows 2019
mcr.microsoft.com/windows/nanoserver:sac2016 ==> Windows 2016
Important: The Windows container must match the Windows host that it will be running on.
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'
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.
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.
UPDATE 3
I checked ($env:path).Split(";") in PowerShell and the Docker path is there:
How can I install Docker?
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.
Inside Dockerfile
# escape=`
FROM microsoft/iis
SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-ASP
WORKDIR /inetpub/wwwroot
COPY . .
Once I build I get the below error
Step 3/5 : RUN Install-WindowsFeature Web-ASP ---> Running in
f1b57ea65228 Install-WindowsFeature : The request to add or remove
features on the specified server failed. Installation of one or more
roles, role services, or features failed. Error: 0x800f0922 At line:1
char:1
+ Install-WindowsFeature Web-ASP
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (#{Vhd=; Credent...Name=localh ost}:PSObject) [Install-WindowsFeature],
Exception
+ FullyQualifiedErrorId : DISMAPI_Error__Failed_To_Enable_Updates,Microsof
t.Windows.ServerManager.Commands.AddWindowsFeatureCommand
Success Restart Needed Exit Code Feature Result
------- -------------- --------- -------------- False No Failed {}
The command 'powershell -command Install-WindowsFeature Web-ASP'
returned a non-zero code: 1
Good morning.
I am working with Docker for Windows 19.03.8, build afacb8b; running on Windows Server 2019 (10.0.17763.1039)
when I run Docker-Compose up -dV it says something like:
Creating network "docker_default" with the default driver
Creating docker_python-base_1 ... done
Creating docker_msbuild_1 ... done
but when I then use Docker-Compose exec, it says:
ERROR: No container found for msbuild_1
in other words, the UP and the EXEC are not using the same (default?) container name.
Al-waleed Shihadeh asked for more info (thanks you !!!!). so....
my docker-compose.yml file:
version: '3.7'
services:
python-base-srv:
build:
context: ./images/python-base
dockerfile: Dockerfile-PythonBase
image: mycompany/builds-win-base-python:3.7.6
volumes:
- ../../..:C:/bldroot
command: powershell -NoExit -NonInteractive
msbuild-srv:
build:
context: ./images/msbuild
dockerfile: Dockerfile-msbuild
image: mycompany/builds-win-msbuild:15.0
volumes:
- ../../..:C:/bldroot
depends_on:
- python-base-srv
command: powershell -NoExit -NonInteractive
Dockerfile-msbuild:
# escape=`
ARG FROM_IMAGE=mycompany/builds-win-base-python
FROM ${FROM_IMAGE} AS build
SHELL [ "powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
RUN Invoke-WebRequest 'https://aka.ms/vs/15/release/vs_buildtools.exe' -OutFile C:\Downloads\vs_buildtools.exe -UseBasicParsing ; `
Start-Process -FilePath 'C:\Downloads\vs_buildtools.exe' -Wait `
-ArgumentList `
'--quiet', `
'--norestart', `
'--locale en-US', `
'--installPath C:\BuildTools', `
'--nocache', `
'--addProductLang en-US', `
'--add Microsoft.Net.Component.3.5.DeveloperTools', `
'--add Microsoft.Net.Component.4.5.TargetingPack', `
'--add Microsoft.Net.ComponentGroup.4.6.1.DeveloperTools', `
'--add Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools', `
'--add Microsoft.Net.ComponentGroup.TargetingPacks.Common', `
'--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP' ; `
Remove-Item c:\Downloads\vs_buildtools.exe -Force
RUN $PATH = $env:PATH + ';C:\BuildTools\MSBuild\15.0\Bin' ; `
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $PATH
# Start developer command prompt before running the specified command (from RUN/EXEC commandline)
COPY ["VsDevCmdPowerShell.bat", "C:\\BuildTools\\"]
ENTRYPOINT ["cmd", "/k", "C:\\BuildTools\\VsDevCmdPowerShell.bat"]
Dockerfile-PythonBase:
# escape=`
ARG FROM_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2019
FROM ${FROM_IMAGE} AS python-base
SHELL [ "powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
RUN `
New-Item -Path C:\Downloads -ItemType Directory ; `
New-Item -Path C:\path -ItemType Directory ; `
`
$PATH = 'C:\path;' + $env:PATH ; `
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $PATH ; `
`
Invoke-WebRequest 'https://www.python.org/ftp/python/3.7.6/python-3.7.6.exe' -OutFile c:\Downloads\python-installer.exe -UseBasicParsing ; `
Start-Process c:\Downloads\python-installer.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; `
Remove-Item c:\Downloads\python-installer.exe -Force
CMD ["powershell", "-NoExit", "-NoLogo", "cmd", "/c ver", ";", "python", "--version", ";", "nuget", "help | select -First 1", ";"]
Outputs:
C:\work\docker> docker-compose up -dV msbuild-srv
Recreating docker_python-base-srv_1 ... done
Recreating docker_msbuild-srv_1 ... done
C:\work\docker> docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------
docker_msbuild-srv_1 cmd /k C:\BuildTools\VsDev ... Exit 0
docker_python-base-srv_1 powershell -NoExit -NonInt ... Exit 0
C:\work\docker> docker logs docker_msbuild-srv_1
Call VsDevCmd.bat to setup environment . . .
C:\>call C:\BuildTools\Common7\Tools\VsDevCmd.bat
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
powershell -NoExit -NonInteractive
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\>
C:\>
C:\work\docker>
so - it is not leaving the containers running in the compose UP step like it should.
docker run -it works fine:
docker container run -it --name msbuildTesting -v C:/work:C:/bldroot -w c:\bldroot\build mycompany/builds-win-msbuild
it seems that your containers are exiting directly after docker-compose up, you can verify this by issuing these commands
docker-compose ps
or
docker ps -a
you also can check the reason why the containers exited by checking the logs
docker logs ${container_name}
Notes:
1. You should use this command to connect to the container docker-compose exec msbuild ${command}