Powershell crashes microsoft/powershell docker container
See original GitHub issueRunning Docker Edge on MAC OSX 10.12.6 From within iterm2 pulled microsoft/powershell:latest container. spin up the container ok and can docker exec into the container ok
run push in container to start powershell and receive the following output:
root@3d90889506e0:/# pwsh
PowerShell v6.0.2
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS />
Oops, something went wrong. Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 0 Keys:
Exception:
System.DivideByZeroException: Attempted to divide by zero.
at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------
Steps to reproduce
docker pull microsoft/powershell docker run --name=mypowershell -itd microsoft/powershell:latest docker exec -it mypowershell /bin/bash
type pwsh at prompt
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Powershell crashes microsoft/powershell docker container
When running docker run -itd to start the powershell container, since the container is detached, System.Console.BufferWidth and System.Console.
Read more >Docker Container stops after running powershell script
I needed to run a powershell script when container is instantiated. That script will modify a config file with the environment variable value....
Read more >Troubleshoot Windows containers
Having trouble setting up your machine or running a container? We created a PowerShell script to check for common problems.
Read more >"docker login" hangs in PowerShell ISE
Expected behavior Prompt for username, password and email when docker login is invoked in the console pane of PowerShell ISE window.
Read more >Powershell crashes microsoft/powershell docker container
Running Docker Edge on MAC OSX 10.12.6. From within iterm2 pulled microsoft/powershell:latest container. spin up the container ok and can ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My investigation shows that the
DivideByZeroException
exception is caused by having the container detached. When runningdocker run -itd
to start the powershell container, since the container is detached,System.Console.BufferWidth
andSystem.Console.BufferHeight
are both 0, meaning the console windows doesn’t exist, and it’s actually a broken state. That leads to theDivideByZeroException
.I don’t think there is anything to fix in PSReadLine. As a workaround, if you need to start the container in a detached mode, then instead of using the default CMD, which is really just for interactive attached usage, just explicitly specify a command to prevent things from shutting down, such as
Then, you can run
docker exec -it mypowershell /bin/bash
ordocker exec -it mypowershell pwsh
For the “Remote - Container” extension in VSCode, now the extension automatically adds a
docker-compose.yml
file to override the default CMD of a container image. The overriding command is just a loop, to prevents the container from shutting down.So I think you don’t need to do anything extra, and it will just work. If the overriding command is not automatically added, then try adding it by yourself.
The issue seems to be with these lines: https://github.com/PowerShell/PSReadLine/blob/fd1265e385cb4b7b860d8f1452da1ceb347e123e/PSReadLine/Render.cs#L489-L498 i.e. as BufferWidth is zero.
Below’s some additional info (sadly copy-paste is not possible from the Docker for Desktop logs panel, where this info’s available).
<?>