Docker Community Forums

Share and learn in the Docker community.

Suggestions on how to test docker containers using exec commands


(Johnfo) #1

I use docker as part of a build system, traditionally using linux containers but I’m looking to extend the approach to windows ones. As part of the (Jenkins) job I use to build our base docker images, I naturally want to test them too. For the linux ones, I generally use an approach:

cont = $(docker run -d image_to_test sleep 36000)
docker exec ${cont} test command 1
docker exec ${cont} test command 2
docker stop ${cont}
docker rm ${cont}

(Not actually this - actually wrapped in Jenkinsfile-style groovy - but hopefully you get the idea.)

For windows, I want to do something similar. sleep does not work, but I tried:

docker run -d image_to_test timeout 300

Problem is that this does not do its job of staying up for the duration of the test. It seems to finish after a second or two, so by the time I get to the second test command 2, I get the error that the container has stopped.

Has anybody got an alternative suggestion? I also tried “cmd ‘ping -n 300 > 127.0.0.1’” following a suggestion I saw, but it made no difference.

BTW using docker for windows on 2016 Server and images which are microsoft/windowsservercore with a few mods.


(Sam) #3

looks like the syntax is

timeout /T 300

(Johnfo) #4

I’ve tried “timeout /T 300” and even “cmd ‘Timeout /T 300’”, latter in case timeout was a special case. Neither work. My guess is that they don’t run without terminal input, but only a guess. Something specific and that others could repeat:

docker run -d microsoft/windowscoreserver timeout -T 300
docker ps -a

At least in my system, it shows the container as status Exited (1) - at least after a few seconds.


(Sam) #5

try

timeout /t 300 >nul 

so it won’t write its waiting message to the screen


(Johnfo) #6

Could you give me an exact line to use as a mod of the docker run -d… line above that works for you? Tried:

docker run -d microsoft/windowsservercore cmd “timeout -T 300 > nul”

but that did the same thing. not putting in cmd gave an error.


(Sam) #7

i cannot run a windows container anywhere…


(Johnfo) #8

I think I’ve found a solution, thought I’d tried this before but perhaps didn’t get it quite right:

docker run -d microsoft/windowsservercore PING localhost -n 3000


(Sam) #9

cool. good old ping!