【整理】PSRemotingの制約をついつい忘れてしまうのでとりあえずメモ

PSRemotingを使っていると何かと躓くことが多いので、この際、リストアップしておこう。

  • Enter-PSSessionはネストできない。
  • WSLにsshできない。
  • Dockerのコンテナの中に入ることができない。

Windows PowerShell PSSession の実行中は、Enter-PSSession コマンドレットを使用して別の PSSession を実行することはできない。

管理者権限powershellだとlocalhostにEnter-PSSessionできるが、さらにlocalhostにEnter-PSSessionしようとすると怒られる。
これは、異なるPC間でも同じであった。

PS >Enter-PSSession -computername  localhost
[localhost]: PS C:\Users\user1\Documents> Enter-PSSession -computername  localhost
Enter-PSSession : 現在 Windows PowerShell PSSession の実行中のため、Enter-PSSession コマンドレットを使用して別の PSSession を実行することはできません。
    + CategoryInfo          : InvalidArgument: (:) [Enter-PSSession]、ArgumentException
    + FullyQualifiedErrorId : RemoteHostDoesNotSupportPushRunspace,Microsoft.PowerShell.Commands.EnterPSSessionCommand

WSLの中に入れない

WSLを入れているPCにEnter-PSSessionしても、WSLにはsshで入ることはできない。
'Pseudo-terminal will not be allocated'と断られてしまうが、何やらメッセージは表示される。

[localhost]: PS C:\Users\user1\Documents> ssh 192.168.150.210
ssh : Pseudo-terminal will not be allocated because stdin is not a terminal.
    + CategoryInfo          : NotSpecified: (Pseudo-terminal...not a terminal.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.10.60.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Oct  2 15:52:34 JST 2022

  System load:  0.06               Processes:             13
  Usage of /:   1.0% of 250.98GB   Users logged in:       0
  Memory usage: 3%                 IPv4 address for eth0: 192.168.150.210
  Swap usage:   0%


253 updates can be applied immediately.
182 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

New release '22.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


[localhost]: PS C:\Users\user1\Documents>

Dockerのコンテナの中に入ることができない。

コンテナの起動・停止はできるが、exec -it で中に入ろうとすると'docker : the input device is not a TTY'と怒られる。
これも、きっとPseudo-terminalであることが制約になっているのだろう。

[localhost]: PS C:\Users\user1\Documents>>$c = docker container ls -q
[localhost]: PS C:\Users\user1\Documents> docker container exec -it $c /bin/sh
docker : the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'
発生場所 行:1 文字:1
+ docker container exec -it $c /bin/sh
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (the input devic...d with 'winpty':String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

[localhost]: PS C:\Users\user1\Documents>

'mintty'なるものを使っていれば可能性があるのかもしれないが、独立しているソフトではなく前提条件としてインストールしなければならないソフトがあるようなので追求するのは断念した。
コンテナの中に入れないのでは、面倒だが外からコマンドを発行するしかなさそうだ。

なお、起動・停止だけなら文字化けする程度でCONTAINER IDの配列を渡して問題なく実行できた。

[localhost]: PS C:\Users\user1> docker container ls -a -f name=test-.*
CONTAINER ID   IMAGE                 COMMAND                  CREATED      STATUS                  PORTS     NAMES
9bbd5b2256b6   nginx:1.17.6-alpine   "nginx -g 'daemon of窶ヲ"   5 days ago   Exited (0) 3 days ago             test-3
34410af55b73   nginx:1.17.6-alpine   "nginx -g 'daemon of窶ヲ"   5 days ago   Exited (0) 3 days ago             test-2
d892fccc011b   nginx:1.17.6-alpine   "nginx -g 'daemon of窶ヲ"   5 days ago   Exited (0) 3 days ago             test-1
[localhost]: PS C:\Users\user1> $c = docker container ls -a --quiet -f name=test-.*
[localhost]: PS C:\Users\user1> $c
9bbd5b2256b6
34410af55b73
d892fccc011b
[localhost]: PS C:\Users\user1> docker container start $c
9bbd5b2256b6
34410af55b73
d892fccc011b