My container said Up and had nothing running in it
My workflow tool was dead for about 17 hours while Docker reported its container as up and its port stayed open. Why the restart policy never fired, and the small watchdog that checks the application itself.
docker ps said the container had been up for 20 hours. docker top on the same container printed its column headers and no processes. Both were accurate. My workflow tool had been dead for about 17 hours, from July 18 into July 19, and every status I normally glance at said it was running.
What I saw
The tool is n8n, running as a Docker container on a small host in my lab. Here is what each check reported when I found it.
| Check | Result | |---|---| | Container status | Up 20 hours | | Running flag | true | | Exit code | 0 | | Killed for memory | false | | Restart count | 0 | | Published port | accepting connections | | Processes in the container | none | | The tool's health endpoint | no response |
Read the first six rows alone and the service looks healthy.
The port deserves a note. On my host, a Docker proxy process holds a published port open on the container's behalf. That process was fine, so a connection to the port succeeded and then went nowhere. A check that only asks whether the port is open would have passed the whole time.
The row that settled it is not in the table. One of my workflows runs every five minutes. Over 17 hours it should have run about 200 times, and its history showed no runs at all.
When I restarted the container, the tool's first log lines reported that the last session had crashed. So the application process had died, and the container had stayed up without it. I did not find out why the container outlived its process.
Why the restart policy did nothing
The service had a restart policy of unless-stopped, which I had taken to mean that Docker would bring the tool back if it died.
Docker's documentation defines the policies by what the container does. For always, it says: "Always restart the container if it stops." It describes unless-stopped as similar to always. The trigger in both is the container stopping. Mine never stopped. From Docker's side nothing had happened. There was no exit and no exit code to react to, which is why the restart count read zero. The policy did exactly what the documentation says.
The restart policy is triggered by the container stopping. The container never stopped, so nothing restarted it.
The service also had no health check, and that part is mine. Docker has a mechanism for this case. The Dockerfile reference says the HEALTHCHECK instruction "tells Docker how to test a container to check that it's still working," and gives the example of "a web server stuck in an infinite loop and unable to handle new connections." A health check runs a command of your choosing on an interval and marks the container healthy or unhealthy by the result.
One limit is worth knowing before you rely on that. The same reference describes the status changing to unhealthy and an event being generated when it does. It does not describe a restart. On a single host running Compose, I was not willing to assume one, so I built the restart myself.
The watchdog
On July 19 I added a small script and a systemd timer on the host that runs the container. Every five minutes it does the following.
- It requests the tool's health endpoint. The n8n documentation says of it: "200 indicates the instance is reachable."
- If that fails, it waits 15 seconds and tries once more.
- If it fails again, it recreates the container and sends me a message.
- It will not act again for ten minutes, so a service that cannot start does not turn into a restart storm.
Then I tested it with a failure the restart policy is designed to ignore. Docker's documentation says: "If you manually stop a container, the restart policy is ignored until the Docker daemon restarts or the container is manually restarted." I stopped the container by hand. The watchdog saw no response from the health endpoint and no processes, recreated the container, and logged a recovery 45 seconds later.
Two caveats come with it.
A deliberate stop now lasts at most five minutes. If I take the tool down for maintenance, I have to disable the timer first, or the watchdog will helpfully undo my work.
The watchdog also runs on the same host as the thing it watches. If the whole host is down, it is down too. I wrote in May about monitors that live on the machine they monitor, and this is one more of them. It covers a dead application on a live host and nothing wider than that.
What else happened that day
July 19 turned out to be an expensive day for this one container. It is the day a fresh image was pulled under the latest tag, which moved the tool to a new major version without my knowing. I wrote about the consequences of that in August. I have no evidence that either problem caused the other. They happened to the same container on the same day.
Checking at the application layer
There are at least three different questions hiding inside "is it up."
Does the container exist and report as running? This is what docker ps answers, and what a restart policy reacts to. Mine passed.
Is the port open? This is what a basic TCP monitor answers. Mine passed, thanks to the proxy.
Does the application answer a real request? This is what a health endpoint answers. Mine failed, and nothing was asking.
There is a fourth question that I trust more than any of them: is the work getting done? A workflow that should run every five minutes leaves evidence every five minutes. Counting that evidence does not depend on the tool's opinion of its own health. In August I moved one pipeline's state into a database table for a related reason. A row count can be checked from outside the tool that writes it.
For a tool like this one, the health endpoint is also the weaker of two that it offers. The n8n documentation describes a readiness endpoint that returns 200 only "if the DB is connected and migrated and therefore the instance is ready to accept traffic." If the question is whether the service can do its job, that is the better one to poll.
The same watchdog pattern belongs beside any container whose silence would cost me something. For each one, the setup is a request that only a working application can answer, a retry so that one slow response does not trigger a restart, an action, a cooldown and a message.
At work this is usually handled by the platform, and the same gap still appears when the health check is weak. A check that returns 200 from a static route tells you the web server is alive. It says nothing about the database connection or the queue behind it. Whoever owns the application owns the definition of healthy, because the platform team cannot know what a working instance of your service looks like.
My own mistake was simpler than any of that. I looked at the container's status and never asked the application anything.
Sources
Views are my own.