Search code examples
powershelldockerdockerfiledocker-for-windows

Running interactive container with power shell


I'm trying to setup an automated build container in Windows(host and guest). Right now I'm having problems executing a simple powershell inside the container. I've done the following:

Created this DockerFile:

# escape=`

FROM microsoft/windowsservercore
SHELL ["cmd", "/S", "/C"]
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

Executed this build command:

docker build -t test:latest .

Started the docker with this command:

docker run test

The PowerShell prints this and the container exits:

PS C:\>

D:\repo\docker\Teste

Tried again with this command:

docker start d05ee -ai

The PowerShell prints the same output:

PS C:\>

D:\repo\docker\Teste

I wish to use the container interactively in a first moment to validate the tools I will install on it, but I'm not able to do that. I don't now which error is blocking me to do it and that is my question.

Obs1: The powershell in a windows cmd with the same parameters work fine.

Obs2: I've based my DockerFile on the one in this tutorial.

Obs3: Running this works fine:

docker run -it microsoft/windowsservercore powershell -NoLogo -ExecutionPolicy Bypass

Therefore I presume the problem is on the image generation.


Solution

  • you need to run your container with the -it switch. this will make you container interactive, so you can poke around

     docker run -it test