0
0
Dockerdevops~15 mins

Restart policies in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Docker Container Restart Policies
📖 Scenario: You are managing a Docker container that runs a simple web server. You want to make sure the container restarts automatically if it stops unexpectedly, so your service stays available without manual intervention.
🎯 Goal: Learn how to set Docker container restart policies to control automatic restarts.
📋 What You'll Learn
Create a Docker container running the nginx image
Add a restart policy configuration
Use the 'always' restart policy
Verify the container restart policy is set correctly
💡 Why This Matters
🌍 Real World
Restart policies help keep important services running automatically without manual restarts, improving reliability.
💼 Career
Understanding Docker restart policies is essential for DevOps roles managing containerized applications in production.
Progress0 / 4 steps
1
Create a Docker container named mynginx using the nginx image
Run the command to create and start a Docker container named mynginx using the nginx image without any restart policy.
Docker
Need a hint?

Use docker run -d --name mynginx nginx to start the container in detached mode.

2
Add a restart policy variable called restart_policy with the value always
Define a variable called restart_policy and set it to the string always to represent the Docker restart policy you want to use.
Docker
Need a hint?

Write restart_policy='always' to set the restart policy variable.

3
Run the Docker container mynginx with the restart policy always
Use the docker run command with the --restart option set to the restart_policy variable value to start the container named mynginx using the nginx image.
Docker
Need a hint?

Use docker run -d --name mynginx --restart $restart_policy nginx to apply the restart policy.

4
Verify the restart policy of the mynginx container
Run the command docker inspect --format='{{.HostConfig.RestartPolicy.Name}}' mynginx to display the restart policy of the container named mynginx.
Docker
Need a hint?

The output should be always indicating the restart policy is set correctly.