I'm using Windows server 2016 to spin up windowsservercore
docker containers and am noticing what I think is incorrect behavior where the container exits very quickly even though it should be sleeping for over 15 minutes. I have the following Dockerfile
:
FROM microsoft/windowsservercore
RUN powershell Start-Sleep -s 1000
I build the container with docker build -t mybuild .
when in the same directory as the Dockerfile
. I then run the container with docker run mybuild
and it exits very quickly.
Looking at this answer it seems that a sleep should keep the container alive. That answer was showing Linux so not sure if that matters but I feel like the sleep process is running in either case and that's what determines if the container should exit or not on default
If I use interactive mode and/or (I tried all 3 combinations) a tty (docker run -it mybuild
) it stays up until I exit the container's shell
Looking at the docker docs run
executes the container in the foreground (like -it) although I don't understand why that would matter since the process should still be running regardless of the container being detached or not. I also tried running it in detached mode with docker run -d
and it exits very quickly in that case as well.
I also tried running another command after the sleep but that still didn't work. The docker file then looked like:
FROM microsoft/windowsservercore
RUN powershell Start-Sleep -s 1000
RUN echo "hello" > C:\hello.txt
I looked at the dockerfile reference for RUN
and it says that RUN
in shell form executes the command using cmd /S /C
on Windows. So I tried running this from my normal shell on my host Windows machine exactly like the Dockerfile
specifies (cmd /S /C powershell Start-Sleep -s 1000
) and verified that it works as expected.
What am I not understanding here? I'm new to docker and trying to learn but I can't figure out what's going on searching the internet and reading docs