DCA · Question #45
DCA Question #45: Real Exam Question with Answer & Explanation
The correct answer is C: 'docker run -d --restart unless-stopped redis'. The docker run command uses the --restart flag with the unless-stopped policy to ensure a container automatically restarts unless manually stopped or the Docker daemon is restarted.
Question
Which of the following commands starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted?
Options
- A'docker run -d --restart-policy unless-stopped redis'
- B'docker run -d --restart omit-stopped redis'
- C'docker run -d --restart unless-stopped redis'
- D'docker run -d --failure omit-stopped redis'
Explanation
The docker run command uses the --restart flag with the unless-stopped policy to ensure a container automatically restarts unless manually stopped or the Docker daemon is restarted.
Common mistakes.
- A. The correct flag for setting a restart policy is
--restart, not--restart-policy. - B.
omit-stoppedis not a valid restart policy; the correct policy for this behavior isunless-stopped. - D.
--failureis not a validdocker runflag for restart configuration, andomit-stoppedis not a valid policy.
Concept tested. Docker container restart policies
Reference. https://docs.docker.com/config/containers/container-start-options/#restart-policies
Topics
Community Discussion
No community discussion yet for this question.