Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider setting the SHELL to pwsh in Docker images #394

Closed
MichaelSimons opened this issue Feb 21, 2018 · 9 comments
Closed

Consider setting the SHELL to pwsh in Docker images #394

MichaelSimons opened this issue Feb 21, 2018 · 9 comments

Comments

@MichaelSimons
Copy link

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.
@tehshwann
Copy link

tehshwann commented Mar 14, 2018

I could be mistaken... but I think 'SHELL' only applies to the 'RUN' in the DockerFile.

I was doing something similar for use of AWSPowerShell .Net Core SDK and I was able to get this working use case working like this:

# escape=`
FROM microsoft/powershell:latest

SHELL ["/usr/bin/pwsh", "-c"]
RUN $ErrorActionPreference='Stop'; `
    Start-Transcript -path /Dockerfile.log -append -IncludeInvocationHeader ; `
    $PSVersionTable | Write-Output ; `
    Install-Module -Name AWSPowerShell.NetCore -AllowClobber -Force ; `
    New-Item /root/.config/powershell/ -Type Directory -Force ; `
    Stop-Transcript ;

# Copy in my custom powershell module files that are "imported" in the profile bellow
ADD ./ /mnt/MyCustomPSM1Dir

# Use pwsh profile to initialize my custom powershell module
ADD ./MyCustom.PowerShell_profile.ps1 /root/.config/powershell/Microsoft.PowerShell_profile.ps1

# Default commands to pwsh
ENTRYPOINT ["pwsh","-c"]

Then I run docker build . -t awspowershellsdk followed by docker run -v $HOME/.aws/:/root/.aws/ awspowershellsdk Get-EC2Instance to load my personal profile into the root usr profile in the container to allow AWSSDK to use my IAM user creds.... and BLAM... I can get all the AWS things I want...

@TravisEz13 TravisEz13 transferred this issue from PowerShell/PowerShell Mar 23, 2020
@ghost ghost added the Needs: Triage 🔍 label Mar 23, 2020
@ghost ghost assigned TravisEz13 Mar 23, 2020
@TravisEz13
Copy link
Member

Shell is already set as @tehshwann explains it has limited scope.

@TravisEz13
Copy link
Member

Please file docker image question in PowerShell/PowerShell-Docker for faster triage.

@ghost
Copy link

ghost commented Mar 24, 2020

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

@ghost ghost closed this as completed Mar 24, 2020
@TravisEz13
Copy link
Member

When I get time, I am considering changing the entry point and command to have a similar effect.

@MichaelSimons
Copy link
Author

I could be mistaken... but I think 'SHELL' only applies to the 'RUN' in the DockerFile.

You are correct. That is the purpose of the SHELL instruction. The CMD and ENTRYPOINT instruction do not affect the shell used in the RUN instructions. Setting the SHELL would make the PS images more useful as a base image where you want to utilize PS within your Dockerfile

Shell is already set as @tehshwann explains it has limited scope.

I don't see it set in the PS images. You can test it out yourself by building the following Dockerfile. It will fail while running Get-ChildItem because it is not being executed within PS.

FROM mcr.microsoft.com/powershell:latest
RUN Get-ChildItem

I see it set in the Nano Server Dockerfiles but it is only set in the installer-env stage and isn't set in the final stage.

Please consider changing this as it really does make the PS images more useful.

I should also point out if you do consider making this change, it should only be done during the next major/minor release as it should be considered a breaking change.

@TravisEz13
Copy link
Member

I agree with the change, but it would be a breaking change for customers that assume that the shell is bash or cmd .

@joeyaiello
Copy link

Had an offline conversation with @TravisEz13. Totally agree that this would be the right thing to do if we were starting fresh, but it's a pretty significant change for both Windows and Linux users.

@MichaelSimons do you or anyone on the .NET team have any experience with making such significant changes to a shipping production container image? Is there some kind of transition path that we can build to make things less (or altogether not) breaking?

@SteveL-MSFT
Copy link
Member

@PowerShell/powershell-committee reviewed this. This is too big of a breaking change to accept at this time. The workaround to set the shell default seems acceptable or calling pwsh explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants