使用 power shell 运行交互式容器

Cri*_*ujo 5 powershell docker dockerfile docker-for-windows

我正在尝试在 Windows(主机和来宾)中设置自动构建容器。现在我在容器内执行简单的 powershell 时遇到问题。我做了以下事情:

创建了这个 DockerFile:

# escape=`

FROM microsoft/windowsservercore
SHELL ["cmd", "/S", "/C"]
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
Run Code Online (Sandbox Code Playgroud)

执行此构建命令:

docker build -t test:latest .
Run Code Online (Sandbox Code Playgroud)

使用以下命令启动 docker:

docker run test
Run Code Online (Sandbox Code Playgroud)

PowerShell 打印此内容并且容器退出:

PS C:\>

D:\repo\docker\Teste
Run Code Online (Sandbox Code Playgroud)

使用此命令再次尝试:

docker start d05ee -ai
Run Code Online (Sandbox Code Playgroud)

PowerShell 打印相同的输出:

PS C:\>

D:\repo\docker\Teste
Run Code Online (Sandbox Code Playgroud)

我希望首先以交互方式使用容器来验证我将在其上安装的工具,但我无法做到这一点。我现在不知道哪个错误阻止了我这样做,这就是我的问题。

Obs1:具有相同参数的 Windows cmd 中的 powershell 工作正常。

Obs2:我的 DockerFile 基于本教程中的 DockerFile。

Obs3:运行它效果很好:

docker run -it microsoft/windowsservercore powershell -NoLogo -ExecutionPolicy Bypass
Run Code Online (Sandbox Code Playgroud)

因此我认为问题出在图像生成上。

4c7*_*b41 2

您需要使用开关运行容器-it。这将使您的容器具有交互性,因此您可以四处查看

 docker run -it test
Run Code Online (Sandbox Code Playgroud)