Difference between revisions of "Docker start configuration behavior and restart policy"
Jump to navigation
Jump to search
↑ https://stackoverflow.com/questions/43108227/is-it-possible-to-show-the-restart-policy-of-a-running-docker-container
↑ https://docs.docker.com/engine/reference/commandline/update/
↑ docker update --restart=always 90bf248337dc
m (Ant moved page Start configuration behavior and restart policy to Docker start configuration behavior and restart policy) |
|||
(22 intermediate revisions by one other user not shown) | |||
Line 13: | Line 13: | ||
To update restart policy execute: | To update restart policy execute: | ||
− | :<code>[[docker update]]</code><ref>https://docs.docker.com/engine/reference/commandline/update/</ref> --restart=always CONTAINER_ID|CONTAINER_NAME<ref>docker update --restart=always 90bf248337dc</ref> | + | :<code>[[docker update]]</code><ref>https://docs.docker.com/engine/reference/commandline/update/</ref> <code>--restart=always CONTAINER_ID|CONTAINER_NAME</code><ref>docker update --restart=always 90bf248337dc</ref> |
:If the container is started with “--rm” flag, you cannot update the restart policy for it. The AutoRemove and RestartPolicy are mutually exclusive for the container. | :If the container is started with “--rm” flag, you cannot update the restart policy for it. The AutoRemove and RestartPolicy are mutually exclusive for the container. | ||
+ | <pre> | ||
+ | docker inspect -f "{{ .HostConfig.RestartPolicy }}" CONTAINER_NAME | ||
− | + | docker update --restart=no $(docker container ls -aq) | |
+ | |||
+ | docker inspect -f "{{ .HostConfig.RestartPolicy}}" $(docker ps -a -q) | ||
+ | </pre> | ||
+ | |||
+ | == Related commands == | ||
+ | * <code>[[docker inspect]]</code> | ||
+ | * <code>[[docker-compose.yml]]</code> | ||
+ | * [[HEALTHCHECK]] | ||
+ | * [[systemd]] and <code>[[service]]</code> | ||
+ | * <code>[[docker ps]]</code> | ||
+ | * <code>[[docker start]]</code> | ||
+ | * <code>/var/lib/docker/containers/[hash_of_the_container]/[[hostconfig.json]]</code> | ||
+ | * <code>[[virsh autostart]]</code> | ||
== See also == | == See also == | ||
* <code>[[docker inspect]]</code> | * <code>[[docker inspect]]</code> | ||
*{{Docker}} | *{{Docker}} | ||
+ | * {{service}} | ||
[[Category:Docker]] | [[Category:Docker]] | ||
− | [[Category: | + | [[Category:DevOps]] |
Latest revision as of 10:52, 26 December 2022
To configure the start configuration behavior or the restart policy for a container (both of them), use the --restart
flag when using the docker run
command. The value of the --restart
flag can be any of the following:
- Do not automatically restart the container. (the default):
no
- Restart the container if it exits due to an error, which manifests as a non-zero exit code:
on-failure
- Restart the container unless it is explicitly stopped or Docker itself is stopped or restarted:
unless-stopped
- Always restart the container if it stops:
always
The following example starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted:
$ docker run -dit --restart unless-stopped redis
With docker inspect CONTAINER
[1] you can verify RestartPolicy
configuration.
To update restart policy execute:
docker update
[2]--restart=always CONTAINER_ID|CONTAINER_NAME
[3]- If the container is started with “--rm” flag, you cannot update the restart policy for it. The AutoRemove and RestartPolicy are mutually exclusive for the container.
docker inspect -f "{{ .HostConfig.RestartPolicy }}" CONTAINER_NAME docker update --restart=no $(docker container ls -aq) docker inspect -f "{{ .HostConfig.RestartPolicy}}" $(docker ps -a -q)
Related commands[edit]
docker inspect
docker-compose.yml
- HEALTHCHECK
- systemd and
service
docker ps
docker start
/var/lib/docker/containers/[hash_of_the_container]/hostconfig.json
virsh autostart
See also[edit]
docker inspect
- Docker:
docker-compose
, Docker Desktop, Docker Scout, Docker Swarm, Docker Volumes, Docker images management, docker network,docker inspect
,docker volume inspect
,Dockerfile
, Docker Engine release notes,docker kill
,moby
, Docker-in-Docker,docker context
,buildx
,docker tag
,docker system prune
, Docker Hub,hub-tool, /etc/docker/daemon.json
,hostconfig.json
, dockerd, logs, Docker logging, Backup,docker service
,depends on
,--dns, --filter
,--mount
,docker login
,docker build
,apt remove docker.io
,.dockerignore
, docker context ls |docker-machine, .docker/
, PWD,$HOME/.docker/config.json
, Docker ID,--env-file, docker --help
service
,service --status-all, /etc/inittab, service ssh restart
Advertising: