From 5b99d0280f3a0e62e08c2ef23a308a84379a7b78 Mon Sep 17 00:00:00 2001 From: modem7 Date: Wed, 31 May 2023 12:04:57 +0100 Subject: [PATCH] Updating image Updated Dockerfile and scripts with some of the latest PR's, and work from tylerpace. Adding a few files back from original repo such as tests and github workflow. Co-Authored-By: Tyler Pace <4195596+tylerpace@users.noreply.github.com> --- .github/workflows/github-build.yml | 0 Dockerfile | 11 +++++--- README.md | 45 ++++-------------------------- tests/.env | 0 tests/README.md | 0 tests/docker-compose.autoheal.yml | 0 tests/docker-compose.yml | 0 tests/watch-autoheal/Dockerfile | 0 8 files changed, 12 insertions(+), 44 deletions(-) mode change 100644 => 100755 .github/workflows/github-build.yml mode change 100644 => 100755 tests/.env mode change 100644 => 100755 tests/README.md mode change 100644 => 100755 tests/docker-compose.autoheal.yml mode change 100644 => 100755 tests/docker-compose.yml mode change 100644 => 100755 tests/watch-autoheal/Dockerfile diff --git a/.github/workflows/github-build.yml b/.github/workflows/github-build.yml old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile index 1d73a7a..ad668f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,9 @@ -FROM alpine:3.17.3 +# syntax = docker/dockerfile:latest + +FROM alpine:3.18.3 RUN apk add --no-cache curl jq -COPY docker-entrypoint / -ENTRYPOINT ["/docker-entrypoint"] - ENV AUTOHEAL_CONTAINER_LABEL=autoheal \ AUTOHEAL_START_PERIOD=0 \ AUTOHEAL_INTERVAL=5 \ @@ -16,6 +15,10 @@ ENV AUTOHEAL_CONTAINER_LABEL=autoheal \ APPRISE_URL="" \ POST_RESTART_SCRIPT="" +COPY docker-entrypoint / + HEALTHCHECK --interval=5s CMD pgrep -f autoheal || exit 1 +ENTRYPOINT ["/docker-entrypoint"] + CMD ["autoheal"] diff --git a/README.md b/README.md index 956122e..f9bcdcb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Docker Autoheal -Monitor and restart unhealthy docker containers. -Monitor and restart unhealthy docker containers. +Monitor and restart unhealthy docker containers. This functionality was proposed to be included with the addition of `HEALTHCHECK`, however didn't make the cut. This container is a stand-in till there is native support for `--exit-on-unhealthy` https://github.com/docker/docker/pull/22719. @@ -28,21 +27,18 @@ docker run -d \ --name autoheal \ --restart=always \ -e AUTOHEAL_CONTAINER_LABEL=all \ - -e DOCKER_SOCK=tcps://HOST:PORT \ + -e DOCKER_SOCK=tcp://HOST:PORT \ -v /path/to/certs/:/certs/:ro \ willfarrell/autoheal ``` a) Apply the label `autoheal=true` to your container to have it watched. -b) Set ENV `AUTOHEAL_CONTAINER_LABEL=all` to watch all running containers. +b) Set ENV `AUTOHEAL_CONTAINER_LABEL=all` to watch all running containers. c) Set ENV `AUTOHEAL_CONTAINER_LABEL` to existing label name that has the value `true`. -Note: You can also exclude a container (eg. if using `AUTOHEAL_CONTAINER_LABEL=all`) by setting the label `autoheal=false`. - Note: You must apply `HEALTHCHECK` to your docker images first. See https://docs.docker.com/engine/reference/builder/#healthcheck for details. -Use `tcp://` for unencrypted tcp and `tcps://` for TLS enabled connection. -See https://docs.docker.com/engine/security/https/ for how to configure TCP with mTLS. +See https://docs.docker.com/engine/security/https/ for how to configure TCP with mTLS The certificates, and keys need these names: * ca.pem @@ -55,16 +51,6 @@ If you need the timezone to match the local machine, you can map the `/etc/local docker run ... -v /etc/localtime:/etc/localtime:ro ``` -### Apprise configuration -a) Start the Apprise docker container. See: https://hub.docker.com/r/caronc/apprise - -b) Create an Apprise configuration for Autoheal to use: -http://localhost:8000/cfg/autoheal - -See the Apprise wiki for configuration details: https://github.com/caronc/apprise/wiki - -c) Set the `APPRISE_URL` environment variable to use the Apprise configuration: -`APPRISE_URL="http://localhost:8000/notify/autoheal"` ## ENV Defaults ``` @@ -75,9 +61,6 @@ AUTOHEAL_DEFAULT_STOP_TIMEOUT=10 # Docker waits max 10 seconds (the Docker def DOCKER_SOCK=/var/run/docker.sock # Unix socket for curl requests to Docker API CURL_TIMEOUT=30 # --max-time seconds for curl requests to Docker API WEBHOOK_URL="" # post message to the webhook if a container was restarted (or restart failed) -WEBHOOK_JSON_KEY="content" # the key to use for the message in the json body of the request to the webhook url -APPRISE_URL="" # post message to Apprise if a container was restarted (or restart failed) -POST_RESTART_SCRIPT="" # Run the specified script if a container was restarted (or restart failed). Script is run from inside the container. Make sure to mount a host directory with the script you want to run. e.g. `-v ./scripts:/scripts` ``` ### Optional Container Labels @@ -85,30 +68,12 @@ POST_RESTART_SCRIPT="" # Run the specified script if a container was restarte autoheal.stop.timeout=20 # Per containers override for stop timeout seconds during restart ``` -### Post-Restart Script - -Here's an example of how you can execute a script after a restart. - -The following values are passed as arguments: `CONTAINER_NAME`, `CONTAINER_SHORT_ID`, `CONTAINER_STATE`, `RESTART_TIMEOUT`. - -```bash -docker build -t autoheal . - -docker run -d \ - -e AUTOHEAL_CONTAINER_LABEL=all \ - -e POST_RESTART_SCRIPT=/scripts/post_restart.sh \ - -v ./scripts:/scripts \ - -v /var/run/docker.sock:/var/run/docker.sock \ - autoheal -``` - ## Testing ```bash docker build -t autoheal . docker run -d \ -e AUTOHEAL_CONTAINER_LABEL=all \ - -e POST_RESTART_SCRIPT=/scripts/post_restart.sh -v /var/run/docker.sock:/var/run/docker.sock \ - autoheal + autoheal ``` diff --git a/tests/.env b/tests/.env old mode 100644 new mode 100755 diff --git a/tests/README.md b/tests/README.md old mode 100644 new mode 100755 diff --git a/tests/docker-compose.autoheal.yml b/tests/docker-compose.autoheal.yml old mode 100644 new mode 100755 diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml old mode 100644 new mode 100755 diff --git a/tests/watch-autoheal/Dockerfile b/tests/watch-autoheal/Dockerfile old mode 100644 new mode 100755