DevSecOps for BBK
  • Introduction
  • Getting Started
    • Virtual Training Practices
    • Training Plan
    • Tools and Configuration
    • Troubleshooting
  • Docker Fundamentals
    • Docker Setup
    • Docker First Container
    • Docker Network Basics
    • Docker Network Exercise
    • Docker Volume Basics
    • Docker Storage
  • Dockerfile Fundamentals
    • Dockerfile Instructions
    • Dockerfile Environment Variables
    • Dockerfile Build Arguments
    • Non-privileged Containers
    • Dockerfile Order of Execution
    • Dockerfile Volume
    • Entrypoint Command
    • Multiple Stage Build
  • Container Management
    • Containers Start Automatically
  • Docker Security
    • Seccomp Profile
  • Docker Compose
    • Docker Compose Install
    • Docker Compose Commands
    • Docker Compose File
    • Docker Compose Volumes and Network
  • K8s Cluster Setup
    • Minikube Installation
    • Calico Networking
    • K8s Walkthrough
    • K8s Cheat Sheet
  • Understand K8s
    • Pod Connectivity
    • Deployments
    • Service Cluster IP
    • Service NodePort
    • ClusterIP Exercise
    • NodePort Exercise
    • Service LoadBalancer
    • Configmap
    • Secrets
  • Application Lifecycle Management
    • Rolling Updates and Rollback
    • Multi Container Pod
  • K8s Storage
    • Persistent Volume
    • Persistent Volume Claim
    • PVC in POD
  • Istio
    • AKS Setup
    • Kubectl Setup in Windows
    • Istio Setup Manual
    • Istio Demo App
    • Istio Observability
  • Terraform
    • Terraform Setup
    • Terraform Demo
    • Azure Terraform Setup
  • Terraform AWS
    • Terraform AWS Setup
    • Terraform AWS Demo S3
  • Refrences
    • Docker Static Site
    • Docker First Image
Powered by GitBook
On this page
  1. Container Management

Containers Start Automatically

In this lesson, we will look at how to set restart policies for containers, and how that will effect their behavior when the docker service is restarted.

To configure the restart policy for a container, use the --restart flag:

no: Do not automatically restart the container. (the default) on-failure: Restart the container if it exits due to an error, which manifests as a non-zero exit code. always: Always restart the container if it stops. unless-stopped: Similar to always, except that when the container is stopped, it is not restarted even after the Docker daemon restarts.

Automatically Restarting a container:

docker container run -d --name --restart

Step 1: Make sure a container always restarts:

docker container run -d --name always-restart --restart always rivethead42/weather-app:latest

Step 2: Make sure a container restarts unless it's stopped:

docker container run -d --name unless-stopped --restart unless-stopped rivethead42/weather-app:latest

Step 3: Stop and restart your Docker service:

sudo systemctl restart docker

Step 4: List your containers:

docker container ls

Step 5: Stop the unless-stopped container:

docker container stop unless-stopped

Step 6: Stop and restart your Docker service:

sudo systemctl restart docker

Step 7: List your containers:

docker container ls

Step 8: Stop the unless-stopped container:

docker container stop always-restart

Step 9: Stop and restart your Docker service:

sudo systemctl restart docker

Step 10: List your containers:

docker container ls
PreviousContainer ManagementNextDocker Security

Last updated 2 years ago