mirror of
https://github.com/willfarrell/docker-autoheal.git
synced 2024-12-06 19:16:20 +01:00
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>
This commit is contained in:
Regular → Executable
+7
-4
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user