powershell - 使用 powershell 运行交互式容器

标签 powershell docker dockerfile docker-for-windows

我正在尝试在 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/

相关文章:

powershell - 是否可以通过.Key而不是[“Key”]访问Powershell哈希表?

regex - Powershell替换和删除

django - docker-compose 不启动 postgres 图像

node.js - 在 docker 容器上运行 nodejs 应用程序会给出 "Error: Cannot find module '/usr/src/app/nodemon' "

powershell - Powershell别名的多个值

.net - 在 Python 中动态编写 PowerShell CmdLets

selenium - Nightwatch 一直报 502 bad gateway

java - 如何将cloudfoundry-uaa部署为基于tomcat的docker镜像?

dockerfile - URL Rewrite 2.0 在 Docker 上安装失败

Docker:来自守护进程的错误响应:没有这样的 id: