Running a random trivia question container
For the subsequent sections of this chapter, we need a container that runs continuously in the background and produces some interesting output. That’s why we have chosen an algorithm that produces random trivia questions. The API that produces free random trivia can be found at http://jservice.io/.
Now, the goal is to have a process running inside a container that produces a new random trivia question every 5 seconds and outputs the question to STDOUT
. The following script will do exactly that:
while :do curl -s http://jservice.io/api/random | jq '.[0].question' sleep 5 done
If you are using PowerShell, the preceding command can be translated to the following:
while ($true) { Invoke-WebRequest -Uri "http://jservice.io/api/random" -Method GET -UseBasicParsing | Select-Object -ExpandProperty Content | ConvertFrom-Json | ...