From 3afb76cc291c3fa76f97ff1d0ea51dd3061d117f Mon Sep 17 00:00:00 2001 From: Owen Valentine Date: Thu, 6 Apr 2023 18:42:08 +0200 Subject: [PATCH 1/2] Add curl to image --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 1a13d20..7a977ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,3 +29,5 @@ ENV ALLOW_RESTARTS=0 \ VERSION=1 \ VOLUMES=0 COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg + +RUN apk --no-cache add curl From 2bae2cc8408b8253e35116b674479d9882e2c247 Mon Sep 17 00:00:00 2001 From: Owen Valentine Date: Thu, 6 Apr 2023 18:42:20 +0200 Subject: [PATCH 2/2] Add documentation to support healthchecks --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index d123abc..4b48187 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,43 @@ For example, [balenaOS](https://www.balena.io/os/) exposes its socket at `/var/run/balena-engine.sock`. To accommodate this, merely set the `SOCKET_PATH` environment variable to `/var/run/balena-engine.sock`. +## Use healthchecks to assert readiness + +In some cases, you may wish to start other containers or services only once this +container is ready. The image contains `curl`, so you can build useful healthchecks. +For example, with `docker` CLI, assuming `PING=1` (default): + +```sh +docker run -d -v /var/run/docker.sock:/var/run/docker.sock --health-cmd "curl -s http://localhost:2375/_ping | grep 'OK'" --health-interval 5s --health-retries 5 --health-timeout 5s ghcr.io/tecnativa/docker-socket-proxy:edge +``` + +Or with `docker compose`, you can control startup order automatically using `depends_on`: + +```sh +services: + dockerproxy: + image: ghcr.io/tecnativa/docker-socket-proxy:edge + healthcheck: + test: + - CMD-SHELL + - curl -s http://localhost:2375/_ping | grep 'OK' + interval: 5s + retries: 5 + timeout: 5s + restart: unless-stopped + volumes: + - /var/run/docker.sock:/var/run/docker.sock + traefik: + depends_on: + dockerproxy: + condition: service_healthy + image: docker.io/traefik:v2.9.9 + ports: + - 80:80 + - 443:443 + restart: unless-stopped +``` + ## Development All the dependencies you need to develop this project (apart from Docker itself) are