What command is used to restart a running Docker container?
Use docker restart <container_name_or_id> to stop and then start a container again.
Click to reveal answer
beginner
What happens when you run docker restart on a container?
Docker stops the container if it is running, then starts it again. It does not apply any changes made to the container's configuration or environment.
Click to reveal answer
intermediate
How can you restart all running Docker containers at once?
You can use docker restart $(docker ps -q) to restart all running containers by passing their IDs to the restart command.
Click to reveal answer
intermediate
What is the difference between docker restart and docker stop followed by docker start?
docker restart combines stopping and starting in one command, while docker stop and docker start are two separate commands that achieve the same result.
Click to reveal answer
intermediate
Can you specify a timeout when restarting a Docker container? How?
Yes, use docker restart -t <seconds> <container> to set how long Docker waits before forcibly stopping the container.
Click to reveal answer
Which command restarts a Docker container named 'webapp'?
Adocker reload webapp
Bdocker restart webapp
Cdocker reset webapp
Ddocker refresh webapp
✗ Incorrect
The correct command to restart a container is docker restart <container_name>.
What does the -t option do in docker restart -t 5 mycontainer?
ATests the container before restarting
BSpecifies the total restart attempts
CTags the container with a label
DSets the timeout in seconds before forcefully stopping the container
✗ Incorrect
The -t option sets the timeout in seconds Docker waits before killing the container.
How can you restart all running containers with one command?
Adocker restart $(docker ps -q)
Bdocker restart --all
Cdocker restart -a
Ddocker restart *
✗ Incorrect
Using docker restart $(docker ps -q) restarts all running containers by passing their IDs.
What is the effect of running docker restart on a stopped container?
AIt removes the container
BIt does nothing
CIt starts the container
DIt pauses the container
✗ Incorrect
Restarting a stopped container will start it.
Which command sequence is equivalent to docker restart mycontainer?
Hint: Use 'docker restart' plus container name only [OK]
Common Mistakes:
Adding unnecessary flags like -c or --container
Using extra keywords after restart
Confusing restart syntax with other commands
3. What will be the output of the command docker restart myapp if the container myapp is currently stopped?
medium
A. myapp
B. Error: Container is not running
C. Container myapp restarted successfully
D. No output
Solution
Step 1: Understand restart behavior on stopped container
If the container is stopped, docker restart will start it and print the container name.
Step 2: Check Docker CLI output format
The command outputs the container name on success, not a success message or error if stopped.
Final Answer:
myapp -> Option A
Quick Check:
Restart prints container name on success [OK]
Hint: Restart prints container name even if stopped [OK]
Common Mistakes:
Expecting an error if container is stopped
Expecting a success message instead of container name
Thinking restart does nothing if container stopped
4. You run docker restart 123abc but get an error: Error: No such container: 123abc. What is the likely cause?
medium
A. Docker daemon is not running
B. The container is already running
C. The container ID or name is incorrect or does not exist
D. You need to add --force flag to restart
Solution
Step 1: Analyze the error message
The error says no such container, meaning Docker cannot find a container with ID or name '123abc'.
Step 2: Check other options
Running container does not cause this error, Docker daemon not running causes different errors, and --force is not a valid restart flag.
Final Answer:
The container ID or name is incorrect or does not exist -> Option C
Quick Check:
No such container = wrong ID/name [OK]
Hint: Check container ID/name spelling if 'No such container' error [OK]
Common Mistakes:
Assuming container must be stopped to restart
Trying to force restart with invalid flags
Ignoring Docker daemon status
5. You want a container to automatically restart if it crashes or Docker restarts. Which command correctly starts a container named db with this behavior?
hard
A. docker run --restart=always db
B. docker run --restart=never db
C. docker run --restart=on-failure db
D. docker run --restart=unless-stopped db
Solution
Step 1: Understand restart policies
The --restart=always policy restarts the container whenever it stops, including crashes and Docker daemon restarts.
Step 2: Compare other policies
never disables restart, on-failure restarts only on errors, and unless-stopped restarts except when manually stopped.
Final Answer:
docker run --restart=always db -> Option A
Quick Check:
Always restart = auto restart on crash and daemon restart [OK]
Hint: Use --restart=always for auto restart on crash and reboot [OK]
Common Mistakes:
Using --restart=never which disables restart
Confusing on-failure with always
Not setting restart policy at container start
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.