DCA · Question #45
Which of the following commands starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted?
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'
How the community answered
(27 responses)- A4% (1)
- B4% (1)
- C93% (25)
Why each option
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.
The correct flag for setting a restart policy is `--restart`, not `--restart-policy`.
`omit-stopped` is not a valid restart policy; the correct policy for this behavior is `unless-stopped`.
The command 'docker run -d --restart unless-stopped redis' correctly starts a Redis container in detached mode (`-d`) and configures it with the `unless-stopped` restart policy. This policy ensures the container automatically restarts if it exits due to an error or a system reboot, but it will not restart if it is explicitly stopped using `docker stop` or if the Docker daemon itself is stopped.
`--failure` is not a valid `docker run` flag for restart configuration, and `omit-stopped` is not a valid policy.
Concept tested: Docker container restart policies
Source: https://docs.docker.com/config/containers/container-start-options/#restart-policies
Topics
Community Discussion
No community discussion yet for this question.