Docker container self-starting method
Add the parameter when starting the container --restart=always
docker run -it -p 8550:8545 -p 30305:30303 --name=eth-node --restart=always -v /home/sungrow_ethereum:/ethereum-test --entrypoint /ethereum-test/node/init.sh ethereum/client-go:v1.8.12 /ethereum-test/node/node.sh
For docker containers that have been started and running, use update to update:
docker update --restart=always container_id
ps:
The restart strategy for Docker containers is as follows:
- no, the default policy, do not restart the container when the container exits
- on-failure, when the container exits abnormally (exit status is not 0), the container will be restarted
- on-failure: 3, restart the container when the container exits abnormally, and restart up to 3 times
- always, always restart the container when the container exits
- unless-stopped, always restart the container when the container exits, but does not consider the container that has been stopped when the Docker daemon starts
View the number of container restarts
docker inspect -f "{
{ .RestartCount }}" container_id
View the last startup time of the container
docker inspect -f "{
{ .State.StartedAt }}" container_id