====== Overview ======
It is possible that due to unattended updates, a docker container is shutdown because dockerd was restarted. Without a restart policy, it remains “dead” and it is not started again. We encountered this problem at dev02. Thus, the policy should be provided in the run part:
docker run --restart always [..]
Documentation: “**always** Always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted.”
===== Logging =====
To limit the logging, use the following parameters:
docker run --log-opt max-size=50m --log-opt max-file=3 [..]
To see if a running container has this log options, use
docker inspect name_of_container
and search for LogConfig
===== Health Check / Ping =====
In the Dockerfile, add something like
HEALTHCHECK --interval=5m CMD curl http://localhost:8000/health || exit 1''
The CMD has to return exit code 0 for OK and exit code 1 for UNHEALTHY
Then ''%%docker ps%%'' will show something like this:\\
Up 15 minutes (healthy)\\
Keywords: automatic restart dockerd container ping monitoring health check
===== Optimization =====
* Consider ''%%–compress%%'' for docker build
* Each RUN creates a new layer → stack your RUN commands