2nd chunk of `content/manuals/engine/containers/start-containers-automatically.md`
1b46a457052999d9b7eebce9b1f1f9bc676558a1ceabbe37000000010000095b
| `always` | Always restart the container if it stops. If it's manually stopped, it's restarted only when Docker daemon restarts or the container itself is manually restarted. (See the second bullet listed in [restart policy details](#restart-policy-details)) |
| `unless-stopped` | Similar to `always`, except that when the container is stopped (manually or otherwise), it isn't restarted even after Docker daemon restarts. |
The following command starts a Redis container and configures it to always
restart, unless the container is explicitly stopped, or the daemon restarts.
```console
$ docker run -d --restart unless-stopped redis
```
The following command changes the restart policy for an already running
container named `redis`.
```console
$ docker update --restart unless-stopped redis
```
The following command ensures all running containers restart.
```console
$ docker update --restart unless-stopped $(docker ps -q)
```
### Restart policy details
Keep the following in mind when using restart policies:
- A restart policy only takes effect after a container starts successfully. In
this case, starting successfully means that the container is up for at least
10 seconds and Docker has started monitoring it. This prevents a container
which doesn't start at all from going into a restart loop.
- If you manually stop a container, the restart policy is ignored until the
Docker daemon restarts or the container is manually restarted. This prevents
a restart loop.
- Restart policies only apply to containers. To configure restart policies for
Swarm services, see
[flags related to service restart](/reference/cli/docker/service/create.md).
### Restarting foreground containers
When you run a container in the foreground, stopping a container causes the
attached CLI to exit as well, regardless of the restart policy of the
container. This behavior is illustrated in the following example.
1. Create a Dockerfile that prints the numbers 1 to 5 and then exits.
```dockerfile
FROM busybox:latest