Docker service logs日志获取机制:单次缓存还是每次网络拉取?
Great question! Let’s break down exactly how docker service logs retrieves log data, no jargon overload:
No local caching—every command triggers a fresh network fetch
When you rundocker service logs, Docker doesn’t pull from a pre-stored cache on your local machine. Here’s the actual flow:- Your Docker client talks to the Swarm manager node.
- The manager maps out all worker nodes running tasks (containers) for the target service.
- The manager coordinates with each worker node to pull logs directly from the node’s local log storage (usually the default
json-filedriver, saved on the worker’s filesystem). - Logs from all relevant nodes are aggregated and sent back to your client over the network.
Real-time tracking uses continuous network streaming too
If you add the--followflag to monitor live logs, the process stays active: your client keeps a network connection open to receive new log entries the moment they’re generated on the worker nodes—no caching happens here either.Quick note on log storage
Individual container logs live locally on the node where the container runs. Swarm doesn’t have a centralized log cache by default, which is why everydocker service logscall needs to reach out to those nodes to grab the latest data.
内容的提问来源于stack exchange,提问作者Ajay Naredla

