Giter Site home page Giter Site logo

powershell-docker's Introduction

PowerShell-Docker

These Dockerfiles enable running PowerShell in a container for each Linux distribution we support.

This requires Docker 17.05 or newer. It also expects you to be able to run Docker without sudo. Please follow Docker's official instructions to install Docker correctly.

Release

The release containers derive from the official distribution image, such as debian:11, then install dependencies, and finally install the PowerShell package.

These containers live at Microsoft Artifact Registry.

At about 440 megabytes, they are decently minimal, with their size being the sum of the base image (200 megabytes) plus the uncompressed package (120 megabytes), and about 120 megabytes of .NET Core and bootstrapping dependencies.

Community

The Dockerfiles in the community folder were contributed by the community and are not yet officially supported.

Examples

To run PowerShell from using a container:

$ docker run -it mcr.microsoft.com/powershell
Unable to find image 'mcr.microsoft.com/powershell:latest' locally
latest: Pulling from mcr.microsoft.com/powershell
cad964aed91d: Already exists
3a80a22fea63: Already exists
50de990d7957: Already exists
61e032b8f2cb: Already exists
9f03ce1741bf: Already exists
adf6ad28fa0e: Pull complete
10db13a8ca02: Pull complete
75bdb54ff5ae: Pull complete
Digest: sha256:92c79c5fcdaf3027626643aef556344b8b4cbdaccf8443f543303319949c7f3a
Status: Downloaded newer image for mcr.microsoft.com/powershell:latest
PowerShell
Copyright (c) Microsoft Corporation. All rights reserved.

PS /> Write-Host "Hello, World!"
Hello, World!

Known Issues

See Known Issues

Developing and Contributing

Please see the Contribution Guide for general information about how to develop and contribute.

For information specific to PowerShell-Docker see Development.

If you have any problems, please consult the known issues, developer [FAQ][], and GitHub issues. If you do not see your problem captured, please file a new issue and follow the provided template. If you are developing .NET Core C# applications targeting PowerShell Core, please check out our FAQ to learn more about the PowerShell SDK NuGet package.

Also make sure to check out our PowerShell-RFC repository for request-for-comments (RFC) documents to submit and give comments on proposed and future designs.

Legal and Licensing

PowerShell is licensed under the MIT license.

Windows Docker Files and Images

License: By requesting and using the Container OS Image for Windows containers, you acknowledge, understand, and consent to the Supplemental License Terms available on Docker hub:

Telemetry

By default, PowerShell collects the OS description and the version of PowerShell (equivalent to $PSVersionTable.OS and $PSVersionTable.GitCommitId) using Application Insights. To opt-out of sending telemetry, create an environment variable called POWERSHELL_TELEMETRY_OPTOUT set to a value of 1 before starting PowerShell from the installed location. The telemetry we collect fall under the Microsoft Privacy Statement.

Governance

Governance policy for PowerShell project is described here.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

powershell-docker's People

Contributors

adelton avatar adityapatwardhan avatar alexandair avatar anamnavi avatar anmenaga avatar claudeleveille avatar danielssilva avatar danijeljw-rpc avatar dependabot-preview[bot] avatar dependabot[bot] avatar erenes avatar github-actions[bot] avatar gngeorgiev avatar jameswtruher avatar kakurasan avatar kiazhi avatar lantrix avatar mattlorimor avatar microsoft-github-policy-service[bot] avatar muojp avatar pcgeek86 avatar pwshbot avatar rdil avatar sdwheeler avatar step-security-bot avatar stevel-msft avatar tbble avatar travisez13 avatar vboulineau avatar xtqqczze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powershell-docker's Issues

Minor Markdown Issues

  • Bullet point Indentation

- **Adds a new image or tag**
- [ ] Not Applicable
- **OR**
- [ ] Update [README.powershell.md](https://github.com/PowerShell/PowerShell-Docker/blob/master/assets/README.powershell.md)
- [ ] Update [vsts-ci.yml](https://github.com/PowerShell/PowerShell-Docker/blob/master/vsts-ci.yml)

  • Incorrect getLatestTag.ps1 file name

* `#tag#` is replaced by all tags generated by the `getLastedTag.ps1` script.
* `#shorttag#` is replaced by short tags generated by the `getLastedTag.ps1` script.
* `#longtag#` is replaced by long tags generated by the `getLastedTag.ps1` script.

* `getLastestTag.ps1` - This script should use the `Get-DockerTags` command from `tools\getDockerTags` to get the tags that should be used as the tag in the `FROM` statement in the Dockerfile.

  • Incorrect ```docker Linguist languages yaml
    • Recommends to be ```dockerfile





  • Lowercase ```PowerShell Linguist languages yaml
    • Recommends to be ```powershell

```PowerShell

```PowerShell

```PowerShell

  • Need Dockerfile Standards documentation about adding the following comments:
    • Copyright notice
    • Software License
    • Image Description

Must be root to run pwsh in Alpine

Steps to reproduce

Create a DockerFIle that sources an Alpine container of PowerShell as follows:

FROM mcr.microsoft.com/powershell:6.2.0-alpine-3.8

# create a non-root user
RUN addgroup -S pstest && adduser -S -G pstest pstest

# copy the script in a folder:
COPY pstest.ps1 /opt/pstest/

# change permissions for the script:
RUN chmod +xxx /opt/pstest/pstest.ps1

# use the pstest user for the container
USER pstest

# set the entry point
ENTRYPOINT ["/opt/pstest/pstest.ps1"]

Create a PowerShell script that sets the interpreter to pwsh, and then writes "Hello world"

#!/opt/microsoft/powershell/6/pwsh
Write-Host "Hello world"

Expected behavior

The PowerShell script will run and output "Hello world"

Actual behavior

Receive an error stating " exec user process caused "permission denied" "

Upon investigation, found that the permissions on /opt/microsoft/powershell/6/pwsh/ contains:

-rwxrw-rw- 1 root root 122216 Mar 25 17:42 pwsh

which indicates that only root may run pwsh. However, if the same steps are performed using an Ubuntu container, the permissions are:

-rwxr-xr-x 1 root root 106912 Mar 25 17:40 pwsh

Environment data

Docker info:

Containers: 32
 Running: 1
 Paused: 0
 Stopped: 31
Images: 525
Server Version: 18.09.2
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 09c8266bf2fcf9519a651b04ae54c967b9ab86ec
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: UICA:K5OL:GRYP:NCWL:UPFI:UOSJ:7ZTD:XEOW:TPYV:URZT:YIIU:O2UH
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 34
 Goroutines: 66
 System Time: 2019-04-24T19:53:20.4337853Z
 EventsListeners: 2
HTTP Proxy: gateway.docker.internal:3128
HTTPS Proxy: gateway.docker.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

PowerShell info:

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Linux 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

pwsh-preview does not exist in container

Steps to reproduce

'''Launch newly pushed Linux Container azuresdk/azuer-powershell-core

Expected behavior

'''Powershell running in container

Actual behavior

c:\docker container run -it azuresdk/azure-powershell-core
Unable to find image 'azuresdk/azure-powershell-core:latest' locally
latest: Pulling from azuresdk/azure-powershell-core
3b37166ec614: Pull complete
504facff238f: Pull complete
ebbcacd28e10: Pull complete
c7fb3351ecad: Pull complete
2e3debadcbf7: Pull complete
643d5ab5c61e: Pull complete
a8ce5075afa2: Pull complete
13eeea351f16: Pull complete
aedbbd6a1d83: Pull complete
4333ac9a1c63: Pull complete
4bfc231cb25f: Pull complete
8fe9135ed5b4: Pull complete
Digest: sha256:35e4027d51dfef03762492b0091087f9ef1da8ea5f923f208a0ac46dbf03a1b7
Status: Downloaded newer image for azuresdk/azure-powershell-core:latest
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: "pwsh-preview": executable file not found in $PATH": unknown.

Logging into container via --entrypoint "/usr/bin/env" and /bin/sh shows that only /usr/bin/pwsh exists and not pwsh-preview.


Environment data
---------------
''docker ce on windows 10 and sles12sp3

<!-- provide the docker info -->

```sh
> docker info

> $PSVersionTable

preview-nanoserver-1809 temp folder does not have list permissions

Steps to reproduce

PS C:\> dir $env:temp

Expected behavior

listing of what is in temp

Actual behavior

dir : Access to the path 'C:\Windows\TEMP' is denied.
At line:1 char:1
+ dir $env:temp
+ ~~~~~~~~~~~~~
+ CategoryInfo          : PermissionDenied: (C:\Windows\TEMP:String) [Get-ChildItem], UnauthorizedAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Environment data

> docker info
Containers: 34
 Running: 0
 Paused: 0
 Stopped: 34
Images: 32
Server Version: 18.09.2
Storage Driver: windowsfilter
 Windows:
Logging Driver: json-file
Plugins:
 Volume: local
 Network: ics l2bridge l2tunnel nat null overlay transparent
 Log: awslogs etwlogs fluentd gelf json-file local logentries splunk syslog
Swarm: inactive
Default Isolation: hyperv
Kernel Version: 10.0 17763 (17763.1.amd64fre.rs5_release.180914-1434)
Operating System: Windows 10 Enterprise Version 1809 (OS Build 17763.379)
OSType: windows
Architecture: x86_64
CPUs: 8
Total Memory: 63.89GiB
Name:
ID: I7LI:SXDK:AL5D:G2ZW:3ZSH:74JP:CUI5:IBH7:2VFK:6Y7T:EUCG:N7QY
Docker Root Dir: C:\ProgramData\Docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Live Restore Enabled: false
Product License: Community Engine
> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.0-rc.1
PSEdition                      Core
GitCommitId                    6.2.0-rc.1
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Images for for Windows Server 2019 (1809)

Currently there doesn't seem to be a powershell docker images based on core or nano that is compatible with with Windows Server 2019 (1809) hosts. A nanoserver image is already available via mcr.microsoft.com/windows/nanoserver:1809.

Document files and fields for this repo

The tags.json is the tag format for the image.

The psVersions.json is the version of PowerShell we will build an image for.

getLatestTag.ps1 returns a structure telling us a tag to build from and how to represent that tag in the tag template. Here are the properties of the structure:

Name description
Tag What we should tag the image
Type Full or Short. Some images have two representations of the same tag. A full descriptive tag, and short. Just say which one the 'Tag' property is. For example for xenial, a short tag would be xenial and a long tag would be xenial-20180525.
FromTag the tag we should build the image from. We should try to use the most descriptive tag. For example for Ubuntu, I would use xenial-20180525

There is a helper here which can generate these for you most of the time.

BlackArch and ArchLinux failing

downloading libcroco-0.6.12+4+g9ad7287-2-x86_64.pkg.tar.xz...
checking keyring...
checking package integrity...
�[91merror: ncurses: signature from "Levente Polyak (anthraxx) <[email protected]>" is unknown trust
�[0m:: File /var/cache/pacman/pkg/ncurses-6.1-4-x86_64.pkg.tar.xz is corrupted (invalid or corrupted package (PGP signature)).
Do you want to delete it? [Y/n] �[91merror: failed to commit transaction (invalid or corrupted package)
�[0m
Errors occurred, no packages were upgraded.
The command '/bin/sh -c echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen     && locale-gen     && pacman -Syy     && pacman -S --noconfirm       core/icu       openssl-1.0     && mkdir -p ${PS_INSTALL_FOLDER}     && tar zxf /tmp/powershell-linux.tar.gz -C ${PS_INSTALL_FOLDER}     && rm -f /tmp/powershell-linux.tar.gz     && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh     && pwsh         -NoLogo         -NoProfile         -Command "           \$ErrorActionPreference = 'Stop' ;           \$ProgressPreference = 'SilentlyContinue' ;           while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) {              Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ;             Start-Sleep -Seconds 6 ;           }"     && pacman -Syyu --noconfirm     && yes | pacman -Scc' returned a non-zero code: 1

@kiazhi
tmpFdyRYx.tmp.txt

Source image for openSUSE needs to be updated

This image has been deprecated in favor of the opensuse/leap and opensuse/tumbleweed images provided and maintained by the openSUSE Project release team.

leap is the equivalent of what we were using

CI failing

Basically the CI is failing on parrot and one Kali platform I can’t remember.
Cc @kiazhi

Fix the `displayName` and `-TestLogPostfix` `String` in the Phase.yml file

Issue
Community release job steps are displaying incorrect displayName and log file name.

displayName: $(ImageName) Servicing
condition: succeededOrFailed()
- ${{ if eq(parameters.communityPreview, 'true') }}:
- powershell: ./build.ps1 -build -name '$(ImageName)' -CI -Channel 'community-preview' -TestLogPostfix '$(ImageName)-servicing'
displayName: $(ImageName) Servicing
condition: succeededOrFailed()
- ${{ if eq(parameters.communityServicing, 'true') }}:
- powershell: ./build.ps1 -build -name '$(ImageName)' -CI -Channel 'community-servicing' -TestLogPostfix '$(ImageName)-servicing'
displayName: $(ImageName) Servicing

Originally posted by @TravisEz13 in #101 (comment)

Can't install any PSGallery modules

Steps to reproduce

docker run -it --rm microsoft/powershell pwsh -Command Install-Module InvokeBuild -Force -Verbose

Expected behavior

Module installs successfully

Actual behavior

VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/6/Modules/PackageManagement/coreclr/netcoreapp2.0/Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/6/Modules/PackageManagement/coreclr/netcoreapp2.0/Microsoft.PackageManagement.ArchiverProviders.dll
VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/6/Modules/PackageManagement/coreclr/netcoreapp2.0/Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: Acquiring providers for assembly: /opt/microsoft/powershell/6/Modules/PackageManagement/coreclr/netcoreapp2.0/Microsoft.PackageManagement.NuGetProvider.dll
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='InvokeBuild'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'InvokeBuild'.
VERBOSE: Performing the operation "Install-Module" on target "Version '5.4.1' of module 'InvokeBuild'".
VERBOSE: The installation scope is specified to be 'AllUsers'.
VERBOSE: The specified module will be installed in '/usr/local/share/powershell/Modules'.
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'InvokeBuild' with version '5.4.1' from the repository 'https://www.powershellgallery.com/api/v2'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='InvokeBuild'' for ''.
VERBOSE: InstallPackage' - name='InvokeBuild', version='5.4.1',destination='/tmp/1647089731'
VERBOSE: DownloadPackage' - name='InvokeBuild', version='5.4.1',destination='/tmp/1647089731/InvokeBuild.5.4.1/InvokeBuild.5.4.1.nupkg', uri='https://www.powershellgallery.com/api/v2/package/InvokeBuild/5.4.1'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/InvokeBuild/5.4.1'.
VERBOSE: The SSL connection could not be established, see inner exception.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/InvokeBuild/5.4.1' for '2' more times
VERBOSE: The SSL connection could not be established, see inner exception.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/InvokeBuild/5.4.1' for '1' more times
VERBOSE: The SSL connection could not be established, see inner exception.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/InvokeBuild/5.4.1' for '0' more times
VERBOSE: Downloading package 'InvokeBuild' failed, please make sure 'https://www.powershellgallery.com/api/v2/package/InvokeBuild/5.4.1' is accessable.
WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/InvokeBuild/5.4.1' is not valid.
PackageManagement\Install-Package : Package 'InvokeBuild' failed to download.
At /opt/microsoft/powershell/6/Modules/PowerShellGet/PSModule.psm1:9491 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (/tmp/1647089731...ild.5.4.1.nupkg:String) [Install-Package], Exception
+ FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Environment data

> docker info
Containers: 54
 Running: 0
 Paused: 0
 Stopped: 54
Images: 72
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.93-linuxkit-aufs
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: linuxkit-00155da7f50f
ID: S5MF:PD6Y:BMLE:UW34:PUCA:X7EO:N37P:GFSC:TKJ7:ZFJM:3ZXE:IWO2
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 22
 Goroutines: 47
 System Time: 2018-09-24T23:16:23.6033013Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.15063.1266
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.1266
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Proposal: create a sub-image with `sudo` and other test dependencies

Create a sub-image with sudo and other test dependencies

Motivation

We use our images for CI and the CI system expects sudo to already exist so it does not have to understand all the package management systems.

Proposal

We can have images which have sudo and an image which does not.

These images would be published as mcr.microsoft.com/powershell/test-deps,
allowing us to add any other dependencies that we find are needed for running tests.

Note, this would not have the agent. This is meant for container job in Azure DevOps or CircleCI.

Alternative proposal

Just include it everywhere

sudo is small, so, I propose we just add it to all images.

The images will still default to root. So, it will not be needed by default.

Alternative names

Alternatives to test-deps in mcr.microsoft.com/powershell/test-deps:

  • ci-cd
  • test-tools

cc @kiazhi @RDIL

Consider setting the SHELL to pwsh in Docker images

Steps to reproduce

Build the following Dockerfile

FROM microsoft/powershell:6.0.1-nanoserver-1709
RUN Get-ChildItem

Expected behavior

docker build would succeed. I was expecting the SHELL would be set to pwsh in the powershell images.

SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

This makes it easy to use the PS 'out of the box' in Dockerfiles based on microsoft/powershell.

Actual behavior

docker build fails with the following error

Sending build context to Docker daemon  135.7kB
Step 1/2 : FROM microsoft/powershell:6.0.1-nanoserver-1709
 ---> 7dff9740d9d5
Step 2/2 : RUN Get-ChildItem
 ---> Running in f1c4985fd989
'Get-ChildItem' is not recognized as an internal or external command,
operable program or batch file.

Windows 1809 nanoserver image has corrupted PATH

Steps to reproduce

The following command:

docker run --rm -it mcr.microsoft.com/powershell:nanoserver-1809 pwsh -Command Write-Host $env:Path

outputs ;C:\Program Files\PowerShell

In the original mcr.microsoft.com/windows/nanoserver:1809 image PATH is C:\Windows\system32;C:\Windows;

Expected behavior

PATH is C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell

Details

In the following PR #118 was mentioned that setx command does not work and was created Dockerfile where PATH is set like that:

ENV PATH="$PATH;${ProgramFiles}\PowerShell"

while setx command is working when executed under ContainerAdministrator like that:

# In order to set system PATH, ContainerAdministrator must be used
USER ContainerAdministrator 
RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell"
USER ContainerUser

Originally from the dockerfile for dotnet.

NOTE

This was caused by an issue that updating the PATH by any method other that the DockerFile ENV statement is not persisted in the image.
Here is a link to how we fixed this:
https://github.com/PowerShell/PowerShell-Docker/pull/165/files#diff-27ac98a3293c888d660df1794159c00fR72
And here is the line that sets the path:

ENV PATH="$WindowsPATH;${ProgramFiles}\PowerShell"

How to setup $env:Path in pwsh.exe in powershell:nanoserver-1803 container?

I want build some application use mcr.microsoft.com/powershell:nanoserver-1803, but can't set $env:PATH by SetEnvironmentVariable method.

How to setup $env:Path in pwsh.exe in powershell:nanoserver-1803 container?

Steps to reproduce

Sample Dockerfile

# escape=`

FROM mcr.microsoft.com/powershell:nanoserver-1803
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ENV	REDIS_DIR="C:\Redis;"

# Test1
RUN	$env:PATH = $env:REDIS_DIR + $env:PATH; `
    [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)

Expected behavior

SetEnvironmentVariable is work.

[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)

Actual behavior

Show "Requested registry access is not allowed." error message.

docker build -t kkbruce/redis-test .
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM mcr.microsoft.com/powershell:nanoserver-1803
 ---> cbf80f683980
Step 2/4 : SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
 ---> Running in 4a78633d3ffb
Removing intermediate container 4a78633d3ffb
 ---> b3becf9915a2
Step 3/4 : ENV  REDIS_DIR="C:\Redis"
 ---> Running in 1823528f2e6d
Removing intermediate container 1823528f2e6d
 ---> 6e947483c825
Step 4/4 : RUN  $env:PATH = $env:REDIS_DIR + $env:PATH;     [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)
 ---> Running in ea1135de36b8
Exception calling "SetEnvironmentVariable" with "3" argument(s): "Requested registry access is not allowed."
At line:1 char:116
+ ...  $env:PATH; [Environment]::SetEnvironmentVariable('PATH', $env:PATH,  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : SecurityException

The command 'pwsh -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; $env:PATH = $env:REDIS_DIR + $env:PATH;     [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)' returned a non-zero code: 1

Environment data

> docker info
Client: Docker Engine - Community
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:47:51 2018
 OS/Arch:           windows/amd64
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.24)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:56:41 2018
  OS/Arch:          windows/amd64
  Experimental:     true
> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.1
PSEdition                      Core
GitCommitId                    6.1.1
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Create test-dep images

Please add a comment and say if you are going to work on something. I'll put your name in the list.

cc @RDIL

fix test-dep image for:

  • preview cent-os

Add Test-dep images:

stable (Needed for release automation)

preview (Needed for release automation)

Community-stable

  • archlinux
  • blackarch
  • clearlinux
  • kali-rolling
  • oraclelinux
  • parrot
  • photon

Recommends `$env:PSModuleAnalysisCachePath` to be located in `/var/cache/microsoft/powershell` folder

Recommends the $env:PSModuleAnalysisCachePath variable uses /var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache path instead of /PSModuleAnalysisCache/ModuleAnalysisCache path.

This is to respect the Linux Filesystem Hierarchy Standard defined in 5.5. /var/cache : Application cache data

Current $env:PSModuleAnalysisCachePath Path

    # set a fixed location for the Module analysis cache
    PSModuleAnalysisCachePath=/PSModuleAnalysisCache/ModuleAnalysisCache

Recommended $env:PSModuleAnalysisCachePath Path

    # Set up PowerShell module analysis cache path
    PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache

Affected Dockerfiles:

  1. release\preview\alpine\docker\Dockerfile
  2. release\preview\centos7\docker\Dockerfile
  3. release\preview\debian8\docker\Dockerfile
  4. release\preview\debian9\docker\Dockerfile
  5. release\preview\fedora27\docker\Dockerfile
  6. release\preview\fedora28\docker\Dockerfile
  7. release\preview\opensuse423\docker\Dockerfile
  8. release\preview\ubuntu14.04\docker\Dockerfile
  9. release\preview\ubuntu16.04\docker\Dockerfile
  10. release\preview\ubuntu18.04\docker\Dockerfile
  11. release\stable\alpine\docker\Dockerfile
  12. release\stable\centos7\docker\Dockerfile
  13. release\stable\debian8\docker\Dockerfile
  14. release\stable\debian9\docker\Dockerfile
  15. release\stable\fedora27\docker\Dockerfile
  16. release\stable\fedora28\docker\Dockerfile
  17. release\stable\opensuse423\docker\Dockerfile
  18. release\stable\ubuntu14.04\docker\Dockerfile
  19. release\stable\ubuntu16.04\docker\Dockerfile
  20. release\stable\ubuntu18.04\docker\Dockerfile

Create module analysis cache in containers

Code to create cache

while(!(Test-Path $env:LOCALAPPDATA\Microsoft\Windows\PowerShell\ModuleAnalysisCache)) {
        Write-Host "waiting for cache"
        # Cache takes at least 10 seconds
        start-sleep -seconds 6
}

Powershell nanoserver image missing VS2017 runtime redistributables

Steps to reproduce

download latest nanoserver image with powershell

FROM mcr.microsoft.com/powershell:6.2.1-nanoserver-1809_kb4480116_amd64

Create a container with application or DLLs built using VS2017.

Expected behavior

The application should run in container. At this point in time I would expect nanoserver image to have the VS2017 redistributable DLLs (vcruntime140.dll, concert140.dll, etc.) in Windows\System32


Actual behavior

Runtime DLLs are missing so applications built with VS2017 will not run.


Environment data

> docker info
> $PSVersionTable

Community-Stable - Clear Linux - Invoke-WebRequest issue

Unable to launch pwsh because it cannot find libssl.

Reproduce Issue 1:

docker run --rm -it powershellcommunity:clearlinux-base

Output:

PowerShell 6.1.0
Copyright (c) Microsoft Corporation. All rights reserved.

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

No usable version of the libssl was found

Reproduce Issue 2:

docker run --rm powershellcommunity:clearlinux-base pwsh -nologo -noprofile -c (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json").Content

Output:

No usable version of the libssl was found

Start PowerShell Docker container with 3rd-party modules preloaded

Hi guys,
I'm trying to figure out how to start a PowerShell container with 3rd-party preloaded modules.
The Dockerfile is pretty simple:

# Use an existing docker image as a base 
FROM mcr.microsoft.com/powershell:preview

# Copy Cisco UCS Power Tools
COPY  ./ucspowertoolcore/Cisco.UCS.Core ./usr/local/share/powershell/Modules/Cisco.UCS.Core
COPY  ./ucspowertoolcore/Cisco.UCSManager ./usr/local/share/powershell/Modules/Cisco.UCSManager

But when I build the container and start it using: docker run -it ucs pwsh
And inside a container run Get-Module I didn't see loaded modules.
So why it's not picking up modules from the standard location or how I can update $Env:PSModulePath variable to include custom path or maybe you have better idea to get this done?

clearLinux failing

Update was applied.
�[91mCalling post-update helper scripts.
�[0mnone
�[91m[ERROR] cbm (../src/bootman/bootman.c:L681): Failed to parse given uname release: 4.15.0-1035-azure
[WARNING] cbm (../src/bootman/bootman.c:L70): Unable to parse the currently running kernel: 4.15.0-1035-azure
[ERROR] cbm (../src/lib/files.c:L165): Invalid block device: /
[ERROR] cbm (../src/lib/system_stub.c:L31): Invalid block device: 0:46
Out of memory�[0mUpdate took 13.6 seconds
649 files were not in a pack
Update successful. System updated from version 26790 to version 27030
7 files removed.
Removing intermediate container 047b6f9fc708
 ---> 00d71464b6ab
Step 20/25 : COPY --from=installer-env ["/usr/lib64/libcrypto.so.1.0.0", "/usr/lib64/libcrypto.so.1.0.0"]
COPY failed: stat /var/lib/docker/overlay2/e684ead89bcca76137ccee3c45f720ceab65919b8482a3ee6d5dc6b7a2af45d1/merged/usr/lib64/libcrypto.so.1.0.0: no such file or directory

@kiazhi

Including support for NTLM for the microsoft/docker container

As per PowerShell/PowerShell#8817, the microsoft/docker container does not support NTLM which makes it pretty limited against what you can invoke WinRM with. I was under the assumption that NTLM would be implemented as part of PowerShell or at the very least be included as part of the container.

As per the blogpost at https://blog.quickbreach.io/ps-remote-from-linux-to-windows/, the container at https://hub.docker.com/r/quickbreach/powershell-ntlm/ includes the gssapi library that you need to include in order to include NTLM support.

Status

  • Evaluate other image
  • stable images
    • CentOs7
    • Ubuntu Images
    • Debian Images
    • Fedora Images
    • Alpine
    • openSUSE
  • preview images
    • CentOs7
    • Ubuntu Images
    • Debian Images
    • Fedora Images
    • Alpine
    • openSUSE
  • All Community Stable Images

FYI, there are no plan to do functional validation for this.

Our efforts currently are focusing on SSH remoting.

Requires automated Build, Test, Publish for community's Dockerfile contributions

To encourage PowerShell community to contribute in this PowerShell\PowerShell-Docker repository, we will need the following capabilities in Azure DevOps Pipelines:

  • Build the community's container image in release/community-stable/ folder
  • Test the community's container image with the current test script
  • Publish the community's container image to Docker Hub's pshorg/powershellcommunity namespace

Error Running 6.1 Ubuntu 16.04 container

I installed the latest 6.1 Ubuntu container via docker and receive the following error when starting it.

PS C:\Users\Adam> docker pull mcr.microsoft.com/powershell:6.1.0-ubuntu-16.04
6.1.0-ubuntu-16.04: Pulling from powershell
3b37166ec614: Already exists
504facff238f: Pull complete
ebbcacd28e10: Pull complete
c7fb3351ecad: Pull complete
2e3debadcbf7: Pull complete
643d5ab5c61e: Pull complete
a8ce5075afa2: Pull complete
13eeea351f16: Pull complete
aedbbd6a1d83: Pull complete
4333ac9a1c63: Pull complete
Digest: sha256:3c1b0674fe6bb9443972176a2b3b22dba558cf31be39031b3392a010ea9c8e69
Status: Downloaded newer image for mcr.microsoft.com/powershell:6.1.0-ubuntu-16.04
PS C:\Users\Adam> docker run -it mcr.microsoft.com/powershell:6.1.0-ubuntu-16.04
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"pwsh-preview\": executable file not found in $PATH": unknown.

ArchLinux and BlackArch failing

@kiazhi FYI

2019-02-08T19:31:21.1715042Z VERBOSE: Running docker  build --pull --quiet --build-arg fromTag=latest --build-arg IMAGE_NAME=pshorg/powershellcommunity:6.1.2-archlinux-latest --build-arg PACKAGE_VERSION=6.1.2 --build-arg PS_VERSION=6.1.2 --build-arg VCS_REF=fe1ad41 -t powershell.local:6.1.2-archlinux-latest -t powershell.local:archlinux-latest /home/vsts/work/1/s/release/community-stable/archlinux/docker
2019-02-08T19:32:19.5916885Z WARNING: *** Last 80 lines of log:
2019-02-08T19:32:19.5917075Z WARNING: Total Download Size:   10.83 MiB
2019-02-08T19:32:19.5917129Z WARNING: Total Installed Size:  42.54 MiB
2019-02-08T19:32:19.5917209Z WARNING: Net Upgrade Size:      41.61 MiB
2019-02-08T19:32:19.5917276Z WARNING: 
2019-02-08T19:32:19.5917320Z WARNING: :: Proceed with installation? [Y/n] 
2019-02-08T19:32:19.5917368Z WARNING: :: Retrieving packages...
2019-02-08T19:32:19.5917948Z WARNING: downloading archlinux-keyring-20190123-1-any.pkg.tar.xz...
2019-02-08T19:32:19.5918219Z WARNING: downloading icu-63.1-2-x86_64.pkg.tar.xz...
2019-02-08T19:32:19.5918467Z WARNING: downloading openssl-1.0-1.0.2.q-1-x86_64.pkg.tar.xz...
2019-02-08T19:32:19.5918558Z WARNING: checking keyring...
2019-02-08T19:32:19.5918605Z WARNING: checking package integrity...
2019-02-08T19:32:19.5918648Z WARNING: loading package files...
2019-02-08T19:32:19.5918692Z WARNING: checking for file conflicts...
2019-02-08T19:32:19.5918772Z WARNING: checking available disk space...
2019-02-08T19:32:19.5918816Z WARNING: :: Processing package changes...
2019-02-08T19:32:19.5919042Z WARNING: reinstalling archlinux-keyring...
2019-02-08T19:32:19.5919136Z WARNING: ==> Appending keys from archlinux.gpg...
2019-02-08T19:32:19.5919185Z WARNING: ==> Locally signing trusted keys in keyring...
2019-02-08T19:32:19.5919451Z WARNING:   -> Locally signing key D8AFDDA07A5B6EDFA7D8CCDAD6D055F927843F1C...
2019-02-08T19:32:19.5919536Z WARNING: ==> ERROR: D8AFDDA07A5B6EDFA7D8CCDAD6D055F927843F1C could not be locally signed.
2019-02-08T19:32:19.5919804Z WARNING:   -> Locally signing key DDB867B92AA789C165EEFA799B729B06A680C281...
2019-02-08T19:32:19.5919866Z WARNING: ==> ERROR: DDB867B92AA789C165EEFA799B729B06A680C281 could not be locally signed.
2019-02-08T19:32:19.5920145Z WARNING:   -> Locally signing key 684148BB25B49E986A4944C55184252D824B18E8...
2019-02-08T19:32:19.5920202Z WARNING: ==> ERROR: 684148BB25B49E986A4944C55184252D824B18E8 could not be locally signed.
2019-02-08T19:32:19.5920455Z WARNING:   -> Locally signing key 91FFE0700E80619CEB73235CA88E23E377514E00...
2019-02-08T19:32:19.5920544Z WARNING: ==> ERROR: 91FFE0700E80619CEB73235CA88E23E377514E00 could not be locally signed.
2019-02-08T19:32:19.5921244Z WARNING:   -> Locally signing key 0E8B644079F599DFC1DDC3973348882F6AC6A4C2...
2019-02-08T19:32:19.5921299Z WARNING: ==> ERROR: 0E8B644079F599DFC1DDC3973348882F6AC6A4C2 could not be locally signed.
2019-02-08T19:32:19.5921700Z WARNING:   -> Locally signing key AB19265E5D7D20687D303246BA1DFB64FFF979E7...
2019-02-08T19:32:19.5921759Z WARNING: ==> ERROR: AB19265E5D7D20687D303246BA1DFB64FFF979E7 could not be locally signed.
2019-02-08T19:32:19.5921839Z WARNING: installing icu...
2019-02-08T19:32:19.5922053Z WARNING: installing openssl-1.0...
2019-02-08T19:32:19.5922265Z WARNING: Optional dependencies for openssl-1.0
2019-02-08T19:32:19.5922467Z WARNING:     ca-certificates [installed]
2019-02-08T19:32:19.5922692Z WARNING: :: Running post-transaction hooks...
2019-02-08T19:32:19.5922740Z WARNING: (1/2) Cleaning up package cache...
2019-02-08T19:32:19.5922783Z WARNING: (2/2) Arming ConditionNeedsUpdate...
2019-02-08T19:32:19.5923008Z WARNING: ‌/bin/sh: tar: command not found‌
2019-02-08T19:32:19.5924474Z WARNING: ‌The command '/bin/sh -c echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen     && locale-gen     && pacman -Syy     && pacman -S --noconfirm       archlinux-keyring       core/icu       openssl-1.0     && mkdir -p ${PS_INSTALL_FOLDER}     && tar zxf /tmp/powershell-linux.tar.gz -C ${PS_INSTALL_FOLDER}     && rm -f /tmp/powershell-linux.tar.gz     && ln -s ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh     && pwsh         -NoLogo         -NoProfile         -Command "           \$ErrorActionPreference = 'Stop' ;           \$ProgressPreference = 'SilentlyContinue' ;           while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) {              Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ;             Start-Sleep -Seconds 6 ;           }"     && pacman -Syyu --noconfirm     && yes | pacman -Scc' returned a non-zero code: 127‌
2019-02-08T19:32:19.5924645Z WARNING: 

SetX is not persisting environmental settings on 1809 images (works on 1803)

Steps to reproduce

Build this dockerfile based off your image:

FROM mcr.microsoft.com/powershell:6.2.0-nanoserver-1809

SHELL ["cmd", "/S", "/C"]
USER ContainerAdministrator
ENTRYPOINT C:\Windows\System32\cmd.exe

RUN curl -SL --output %TEMP%\python.zip https://www.nuget.org/api/v2/package/python/3.7.3 \
    && md C:\Python C:\PythonTemp \
    && tar -zxf %TEMP%\python.zip -C C:\PythonTemp \
    && xcopy /s c:\PythonTemp\tools C:\Python \
    && rd /s /q c:\PythonTemp \
    && del /q %TEMP%\python.zip

RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell\;C:\Python;C:\python\scripts" \
    && setx /M PYTHONPATH "C:\Python\Lib;C:\Python\DLLs;"

RUN python -m pip install --upgrade pip

Expected behavior

Installs Python 3 on nano and upgrades pip

Actual behavior

Crashes because `C:\python`'s not on the path

Environment data

> docker info
> $PSVersionTable

Path Issues nanoserver 6.2.0-nanoserver-1809_kb4480116_amd64

Steps to reproduce

Start a container based on the Powershell nanoserver image in title, making CMD the default shell and leave it (CMD) running.
When container starts, type pwsh to start Powershell

Expected behavior

Powershell should start

Actual behavior

Powershell fails to start because C:\Program Files\Powershell is not in the path.

Also, a semicolon appears to be required at the end of the last path entry.

Environment data

> docker info
Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 133
Server Version: 18.09.2
Storage Driver: windowsfilter
 Windows:
Logging Driver: json-file
Plugins:
 Volume: local
 Network: ics l2bridge l2tunnel nat null overlay transparent
 Log: awslogs etwlogs fluentd gelf json-file local logentries splunk syslog
Swarm: inactive
Default Isolation: hyperv
Kernel Version: 10.0 17763 (17763.1.amd64fre.rs5_release.180914-1434)
Operating System: Windows 10 Pro Version 1809 (OS Build 17763.437)
OSType: windows
Architecture: x86_64
CPUs: 8
Total Memory: 63.95GiB
Name: Iguana
ID: xxxxx
Docker Root Dir: C:\ProgramData\Docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: -1
 Goroutines: 62
 System Time: 2019-05-06T14:27:40.4320753-05:00
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
> $PSVersionTable
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.