???? ????????? ????????? ?????
Docker ?? Restart Policy ??????? ???? ?????? ????????????? ?????? ???????????????? ???? ????, ???? ?????????????????? ???? ????? ?? ????? ?????????????? ???? ????? ??? ???????????????? ??????? ???? ?????? ????? ???? ??? ???????? ?????? ????? ?????? Docker ?? ???????? ????? Restart Policy ????? ?????? ????
Restart Policy ?? ??? ????
Docker ?? restart policies ????? ???? ??? ???? ????? ??????????? ??? ??????? ???? ???:
?????? ????? ??? ???? ???? ????? ??? ???? ????? ? YAML ???? ??????? ??? declaratively ??????? ???? ????? Docker Compose, Docker Swarm, ?? Kubernetes ?? ????
Docker ?? ????? ?????? Restart Policy ????
???? ???? ????? ????? ????? ???????? ???? ????
?. always Restart Policy
always Restart Policy ??? ???? ??????????? ?????? ?????? ???? ???? ???? ???? ???? ???? ??? ???? ??? ???? ?????, ???? ??????? ??? ?? ????? ??????????? ??? ??????
????? ???????? ????? ???? ???? ????????? ?????? ???? ???? --restart always ????? ????? ??? ????
mycontainer ????? ???? ???? ????????? ???? ???
alpine ???? ??????? ??? ???? ???? sh ??? ??????
--restart always ?????? ??????? ??? ???? ?????, ?????? ??? ???? ??? ?? ???
??????????? ????? ?????? ????? ps -elf ??? ???? ?????? ?? ??? PID 1 ???? ?????? ????? exit ?????? ????? ??????????? ???? ?????
??????????? ???? ????? ??? docker ps ????? ??????????? ?????? ??????
?????? ?? ??????????? ???? ?????? ?? Docker ??? ???? ???? ?????? ??? docker inspect ????? ??? ??? ???, RestartCount ???? ????? ?????? ????? ??? ??????? ???? ???????
docker inspect mycontainer --format '{{.RestartCount}}'
?. unless-stopped Restart Policy
unless-stopped ??????? always ?? ??? ??? ???, ??? ???????? ?? ??? Docker daemon ????????? ??? ????????? ?????? ????? ????????????? ???? ???, ?????? ?????? ??????? ???? ??? ??? ?????? ???? ???? ???
???? ???? ????????? ??????, ???? always ??? ?????? unless-stopped ????? ?????
???? ??????????? ?????? ????? docker ps ???? ??????????? ?????? ??? ???? ????? ???? ?????????? ?????? ???? docker stop ????? ????? ???? ???? ???? ??? ???? ????????? ???? ?????
always-example ??????????? ??????? ???? ??????
unless-stopped-example ??????????? ???? ???????? ???? ????
?. on-failure Restart Policy:
Docker ?? on-failure ????? ???? ??????? ????? ?? ????????? ????????? ?????? ????? ???? ??? ??????? ???? ???? on-failure ??????? ????????? ???? ?????? ???? ???? ??? ???:
?? ????? ???? ??????? ????? ???? ????? ?????????????? ???? ??????? ?????? ?? self-healing ?????? ?????? ??? ???? ??? ??? ??????????? ????????????? ???? ??? (???? exit code 0 ?????), ????? ??? ??????? ???? ??? ???
??????? ? ??? ?????? ???? ???? ????? ??????? ???? ??????? ???? ????? ???? ??????? ????
Software Engineer | NodeJs | Angular | Java(Spring boot) | MongoDB | PostgreSQL | MSc Uni-Bremen
1 周Thanks for sharing