我正在尝试在 Windows(主机和 guest )中设置自动构建容器。现在我在容器内执行简单的 powershell 时遇到问题。我做了以下事情:
创建了这个 DockerFile:
# escape=`
FROM microsoft/windowsservercore
SHELL ["cmd", "/S", "/C"]
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
执行此构建命令:
docker build -t test:latest .
使用此命令启动 docker:
docker run test
PowerShell 打印此内容并退出容器:
PS C:\>
D:\repo\docker\Teste
再次尝试使用此命令:
docker start d05ee -ai
PowerShell 打印相同的输出:
PS C:\>
D:\repo\docker\Teste
我希望在第一时间以交互方式使用容器来验证我将在其上安装的工具,但我无法做到这一点。我现在不知道是哪个错误阻止了我这样做,这是我的问题。
Obs1:具有相同参数的 Windows cmd 中的 powershell 工作正常。
Obs2:我的 DockerFile 基于 this tutorial. 中的那个
Obs3:运行这个工作正常:
docker run -it microsoft/windowsservercore powershell -NoLogo -ExecutionPolicy Bypass
因此我认为问题出在图像生成上。
最佳答案
您需要使用 -it
开关来运行您的容器。这将使您的容器具有交互性,因此您可以四处闲逛
docker run -it test
关于powershell - 使用 powershell 运行交互式容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53286374/