Linux SWAG container - Is there an option for a healthcheck?

Is there a method to configure via docker-compose a healthcheck on the swag container? I’m aware to configure a healthcheck via a Dockerfile but this would be an add on – taking the base swag container and adding a healthcheck. I didn’t know how if this capability was already built in.

Yes, you can define a healthcheck in your compose: Docker Tip #85: Define HEALTHCHECK in your Docker Compose File — Nick Janetakis

Hey thanks for reply

I’m aware of using curl or other such tools like wget to healthtest a container, however usually there is a port or endpoint that will answer back OK or something similar. In the example you linked to the command:

test: "${DOCKER_HEALTHCHECK_TEST:-curl localhost:8000/healthy}"

localhost:8000/healthy probably answers back OK or something similar.

I was wondering if there was a similar endpoint in the swag container which I could query for a healthcheck.

SWAG is an nginx webserver, so just point it to any address/port that curl can successfully connect to (like the homepage) or just have nginx serve a 200 at an address you pick.

1 Like

@aptalca

Thanks for the suggestion, after just a little bit of reading, I made everything work as you hinted. I know this is such an easy fix, but in general it was kind of hard as a beginner to see how everything came together to make a healthcheck work successfully. The official docker documentation discusses healthcheck and its parameters but never really discussed how to implement such a healthcheck with a container – for example in the use of this nginx container it meant declaring a location block like the following within my proxy subdomain:

server {
        server_name disco.domain.com;
        listen 8000;

        location /health-check {
                add_header Content-Type text/plain;
                return 200 "OK\n";
        }
}

The healthcheck then in my docker-compose file would be implemented like the following:

    ports:
      - 443:443
      - 80:80
      - 8000:8000
    restart: unless-stopped
    healthcheck:
      test: "${DOCKER_HEALTHCHECK_TEST:-curl localhost:8000/health-check}"
      interval: "60s"
      timeout: "3s"
      start_period: "5s"
      retries: 3

After figuring this out, I’m aware healthchecks could be implemented in like a hundred different ways, however just weird I didn’t find any specific basic examples like this putting it all together.

Thanks for your help!!!

Also keep in mind that if there is an available page that loads, you can just use that (ie. no auth). I don’t believe it needs to have the content “ok”. It just needs to load properly with a 200 return code (successful connection).

@aptalca – Thanks for information. Definitely I could simply the setup in most cases with your information. In this particular setup I’m using nginx in front of a reverse proxy for syncthing’s discovery server. I’m not sure exactly how the application exactly works, but it does not serve or return web pages. I’ve read technically to return a 200 something needs to be returned whereas serving no content is technically a 204 – which in some instances breaks a healthcheck in some implementations.

I meant you can use any existing page that loads without auth. For instance if you want to add a healthcheck to tautulli, you can use tautulli’s homepage. You don’t need to create/serve a new page just to satisfy the healthcheck. If swag’s home page loads without auth (perhaps on local networks, which you can do with allow/deny statements in the site conf) then you can just use curl -kL localhost:80