Last updated
Last updated
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:
Step 2: Make sure a container restarts unless it's stopped:
Step 3: Stop and restart your Docker service:
Step 4: List your containers:
Step 5: Stop the unless-stopped container:
Step 6: Stop and restart your Docker service:
Step 7: List your containers:
Step 8: Stop the unless-stopped container:
Step 9: Stop and restart your Docker service:
Step 10: List your containers: