Certain Docker Commands not working in Windows Powershell ISE but working in other Command Line tools - powershell

I am exploring docker and I've been using Windows Powershell ISE to run docker commands. I have come across situation where I run certain commands in Powershell but they appear to be stuck, but when I run the same docker command on Command Prompt they work fine. I am using the same machine but different command line tools. Why do certain docker command work in powershell and some don't? The below are just some examples. While most work, some don't appear to be working.
Example 1) docker system prune
In powershell I expected a message like I do in the command prompt below, but it appears to be hanging.
Example 2) docker exec -ti containerName bash
In CMD Prompt, I am able to jump into my running container but not in Powershell

Docker does not support Powershell-ISE:
https://docs.docker.com/docker-for-windows/

Related

Can't get ssh-keygen to complete using Powershell [duplicate]

I have recently started working with Kubernetes and Docker and still new with how it all works. I have made a ps1 script to run all the steps I need to do to build image and execute image on Kubernetes.
What I see is all steps work fine on ISE (except this one: "kubectl exec -it test-runner pwsh"). For this step alone, I have to run it on another PowerShell window.
When I run this step in ISE, the script keeps running without ever giving any error or stopping.
Does anyone know if its a limitation with Kubernetes working on ISE or if there is a workaround to make it work?
Working with ISE is quick and saves me tons of time, so this really makes a difference when I have to copy, paste, enter this each time in a separate PowerShell window.
Thanks in advance for your help!
P.S: I looked at other suggested similar questions/answers and none of them seem to be related to Kubernetes not working on ISE. Hence this question.
command:
kubectl exec -it test-runner pwsh
Expected (and actual when running from PowerShell console):
----------------------
PS C:\windows\system32> kubectl exec -it test-runner pwsh
PowerShell 6.2.2
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /test>
-----------------------------
Actual (when running from PowerShell ISE):
PS C:\SourceCodeTLM\Apollo> kubectl exec -it test-runner pwsh
PowerShell 6.2.2
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
(with a blinking cursor and script running without breaking and changing to the new path)...
-----------------------------------------------
The PowerShell ISE doesn't support interactive console applications, which notably means that you cannot start other shells from it.
The ISE tries to anticipate that problem by refusing to start well-known shells.
For instance, trying to start cmd.exe fails with the following error message:
Cannot start "cmd". Interactive console applications are not supported.
To run the application, use the Start-Process cmdlet or use
"Start PowerShell.exe" from the File menu.
Note:
pwsh.exe, the CLI of PowerShell (Core) 7+, is not among the well-known shells, which indicates the ISE's obsolescent status. It is being superseded by Visual Studio Code with the PowerShell extension. Obsolesence aside, there are other pitfalls - see the bottom section of this answer.
However, it is impossible for the ISE to detect all cases where a given command (ultimately) invokes an interactive console application; when it doesn't, invocation of the command is attempted, resulting in obscure error messages or, as in your case, hangs.
As the error message shown for cmd.exe implies, you must run interactive console applications outside the ISE, in a regular console window.
From the ISE you can use Start-Process to launch a program in a new, regular console window; in the case at hand:
Start-Process kubectl 'exec -it test-runner pwsh'
Alternatively, run your PowerShell sessions outside the ISE to begin with, such as in a regular console window, Windows Terminal, or in Visual Studio Code's integrated terminal.
After digging out, I found a way to interact with the interactive console applications.
we can use SendKeys('key_here') to specific application.
You could open a command window from PowerShell and send the command to open the shell.
Start-Process PowerShell -Wait "-NoProfile -ExecutionPolicy Bypass -Command `"kubectl exec helloworld-web-8495f4c888-jw2tg -n local-v1 -it -- /bin/bash`""

Execute powershell script with gitlab-runner on local windows machine

I do have following setup:
a win PC with gitlab-runner installed (working)
a powershell script running on the same PC is starting an application
a gitlab server to connect this local PC and starting the powershell script
Now when starting the powershell script directly from the local PC, the application starts and terminates after done - working as expected. When starting the same powershell script with the gitlab server (yml-file) then I can see that the application has been started (new process in taskmanager) but it is not running as well it never terminates.
When manually end the task I see that gitlab terminates again.
Question:
what could be the root cause?
is it possible to run the powershell script with gitlab-runner? I think there is a way with the command "exec". How does the command looks like when calling the powershell script?
is it possible to run the application not in the background in order to see whats going on?
others?
thanks in advance
I think there is a bug with the gitlab runner on windows.
No matter which shell you configure in the config.toml the runner
will always use cmd.exe for an exec local run.
Specify the --shell argument to override the default cmd.exe shell:
> gitlab-runner exec shell your_job --shell pwsh
If you run this locally in your project, it outputs to .builds/, so add this to your .gitignore because git will see it and think you might want to add a submodule.

Run bash script in WSL through powershell script

I am trying to run a script which launches a WSL (ubuntu1804) terminal, and then run a bash script in that terminal
.\ubuntu1804.exe;
cd test_directory;
node server.js;
However after the first command the terminal open however, the two other commands aren't executed
.\ubuntu1804.exe by itself opens an interactive shell which PowerShell executes synchronously.
That is, until you submit exit in that interactive shell to terminate it, control won't be returned to PowerShell, so the subsequent commands - cd test_directory and note server.js - are not only not sent to .\ubuntu1804.exe, as you intended, but are then run by PowerShell.
Instead, you must pass the commands to run to .\ubuntu1804.exe via the run sub-command:
.\ubuntu1804.exe run 'cd test_directory; node server.js'
Note: Once node exits, control will be returned to PowerShell.

Windows - Docker CMD does not execute

For the life of me, I cannot seem to get my provisioning script to execute when I run my container. Down the road, I will need to pass in arguments to the docker run command to replace 'hiiii' and '123' for multiple container deployments.
This is my docker file
FROM microsoft/aspnet:3.5-windowsservercore-10.0.14393.1198
SHELL [“powershell”, “-Command”, “$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;”]
COPY *.ps1 /Container/
COPY [“wwwroot”, “/inetpub/wwwroot”]
COPY [“Admin”, “/Program Files (x86)Admin”]
COPY [“Admin/web.config”, “/Program Files (x86)/Admin/web_default.config”]
#ENTRYPOINT [“powershell”]
CMD [“powershell.exe”, -NoProfile, -File, C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -parm2 ‘123’]
I have also tried the shell version of CMD as follows
CMD powershell -NoProfile -File C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -Parm2 ‘123’
This is the command I am using.
docker image build -t image:v1:v1 .
docker run --name container -p 8001:80 -d image:v1
After I create and run the container I see that the script did not run, or failed. However, I can exec into powershell on the container and run the script manually and it works fine and I see all the changes that I need.
docker exec --interactive --tty container powershell
C:\Container\Start-Admin.Docker.Cmd.ps1 -Parm1 ‘Hiiii’ -Parm2 ‘123’
I am just at a loss as to what I am missing regarding CMD.
Thanks!
I was able to get it working the way I had hoped. Though I am still working out some details in the provisioning script, this is how I ended up getting the result I wanted from the docker side of things.
FROM microsoft/aspnet:3.5-windowsservercore-10.0.14393.1198
#The shell line needs to be removed and any RUN commands need to be immediately proceeded by 'powershell' eg RUN powershell ping google.com
#SHELL [“powershell”, “-Command”, “$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;”]
COPY *.ps1 /Container/
COPY [“wwwroot”, “/inetpub/wwwroot”]
COPY [“Admin”, “/Program Files (x86)Admin”]
COPY [“Admin/web.config”, “/Program Files (x86)/Admin/web_default.config”]
ENV myParm1 Hiiii
ENV myParm2 123
ENTRYPOINT ["powershell", "-NoProfile", "-Command", "C:\\Container\\Start-Admin.Docker.Cmd.ps1"]
CMD ["-parm1 $Env:myParm1 -parm2 $Env:myParm2"]
The docker run command looks like this
docker run -d -p 8001:80 -e "myParm1=byeeeee" --name=container image:v1
I hope this helps someone else that is in my boat. Thanks for all the answers!
You can give this a try. ARG passes the variable to shell accessible via PS $env: variable.
ARG parmOne=Hiiii
ARG parmTwo=123
# Run a native PowerShell session and pass the script as a command.
RUN ["powershell", "-NoProfile", "-Command", "C:\\Container\\Start-Admin.Docker.Cmd.ps1 -Parm1 $env:parmOne -parm2 $env:parmTwo"]

Powershell and ssh when running rabbit

I have ssh on to a ubuntu box and run the following:
rabbitmq-server –detached
Which I believe should give me the command prompt back and run rabbit in the background, howerver it justs hangs:
Is this a powershell issue?
PowerShell is a component of Microsoft Windows, it has a command-line shell and a scripting environment. So I don't think you question is relative to PowerShell.