0
0
Dockerdevops~20 mins

Restarting containers in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Container Restart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of restarting a stopped container?
You have a Docker container named webapp that is currently stopped. You run the command docker restart webapp. What will be the output?
Docker
docker restart webapp
Awebapp restarted
BError: No such container: webapp
CContainer webapp restarted successfully
Dwebapp
Attempts:
2 left
💡 Hint
The restart command returns the container name if successful.
Troubleshoot
intermediate
2:00remaining
Why does docker restart fail with 'No such container'?
You run docker restart mycontainer but get the error Error: No such container: mycontainer. What is the most likely cause?
Docker
docker restart mycontainer
AThe container name or ID is incorrect or does not exist
BDocker daemon is not running
CThe container is paused
DThe container is already running
Attempts:
2 left
💡 Hint
Check if the container name matches exactly.
Configuration
advanced
2:00remaining
How to configure automatic restart of a container on failure?
You want a container to restart automatically only if it crashes (exits with error). Which Docker run option achieves this?
Docker
docker run --restart=? myimage
A--restart=unless-stopped
B--restart=on-failure
C--restart=no
D--restart=always
Attempts:
2 left
💡 Hint
This option restarts only on non-zero exit codes.
🔀 Workflow
advanced
2:00remaining
What is the correct sequence to restart all running containers?
You want to restart all currently running Docker containers with a single command sequence. Which option correctly does this?
Adocker restart $(docker ps -q)
Bdocker ps -q | xargs docker restart
Cdocker ps -a | grep Up | awk '{print $1}' | xargs docker restart
Ddocker restart $(docker ps -a -q)
Attempts:
2 left
💡 Hint
Use only running containers' IDs.
Best Practice
expert
2:00remaining
What is the best practice to ensure a container restarts after Docker daemon reboot?
You want your container to restart automatically after the Docker service or host machine restarts. Which restart policy is best suited for this?
A--restart=on-failure
B--restart=unless-stopped
C--restart=always
D--restart=no
Attempts:
2 left
💡 Hint
This policy restarts containers except when explicitly stopped.