6.2.1.2 Detached Service Runtime
A focused guide to Detached Service Runtime, connecting core concepts with practical Docker and container operations.
Detached service runtime refers to the typical, ongoing operation of a long-running service container started in detached mode, expected to continue running indefinitely until deliberately stopped, rather than completing some finite task and exiting on its own.
What Distinguishes a Service From a One-Off Task
A service container's main process is designed to run continuously — accepting requests, processing a queue, serving traffic — with no natural completion point, in contrast to a one-off task container that performs a specific job and then exits.
docker run -d --name web-server -p 8080:8080 nginx:alpine
This container is expected to remain running indefinitely, serving requests until explicitly stopped, rather than completing and exiting on its own.
Monitoring a Detached Service's Ongoing Health
Because a service container is expected to run continuously, monitoring its ongoing health and resource usage over time is an important part of operating it reliably.
docker stats web-server
docker inspect web-server --format '{{.State.Health.Status}}'
Configuring Automatic Restart for Continuous Availability
A detached service typically benefits from a restart policy, ensuring it automatically resumes running if it crashes or the host restarts.
docker run -d --restart=unless-stopped --name web-server nginx:alpine
Recognizing When a Detached Service Has Unexpectedly Stopped
A service container that has unexpectedly stopped, despite being intended to run continuously, warrants investigation into why, since this represents a deviation from its expected ongoing operation.
docker ps -a --filter "name=web-server"
docker logs web-server
Why Detached Service Runtime Matters
Recognizing a container's role as a continuously running service, rather than a finite task, shapes how it should be configured (restart policies, health checks) and monitored, distinguishing it clearly from containers whose successful completion is expected to result in them exiting on their own.