Docker Swarm healthchecks - checking for file presence

Posted by in DevOps, last updated on 05 March, 2025

Docker swarm configuration

Recently I deployed a service that has no HTTP endpoints, instead I created a file in the container on startup that is deleted when the service is unhealthy.

Here is the config to check for the file presence, once deleted and the healthcheck fails a few times the service will be restarted:

deploy:
   replicas: 1
   restart_policy:
     condition: on-failure
    healthcheck:
      test: ["CMD", "test", "-f", "/path/to/file"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

Or if you’re deploying the apps using Dokploy as I am this is the config:

{
  "Test": [
    "CMD",
    "test",
    "-f",
    "/path/to/file"
  ],
  "Interval": 30000000000,
  "Timeout": 10000000000,
  "StartPeriod": 30000000000,
  "Retries": 3
}

Happpy deploying!

Click here to get $200 free credits with DigitalOcean.

Sign up and get a $200, 60-day credit to try any DigitalOcean product including servers, managed DBs, kubernetes and their app plaftorm.

I don't receive any money as an affiliate however if you end up spending $25 I will receive a $25 credit as well which helps with my hosting and testing more tech :)


Daniel Wachtel

Written by Daniel Wachtel

Daniel is a Full Stack Engineer who outside work hours is usually found working on side projects or blogging about the Software Engineering world.