Open-Source Wikis

/

Moby

/

Primitives

/

Service and Task

moby/moby

Service and Task

Definitions

Swarm-mode primitives:

  • Service — the desired-state spec for an N-replica workload (image, env, mounts, networks, update policy).
  • Task — a single instance of a service assigned to a node.

These types come from SwarmKit and are surfaced through the Engine API in api/types/swarm/.

Wire types

Type File Purpose
Service api/types/swarm/service.go A swarm service.
Task api/types/swarm/task.go A scheduled instance.
Node api/types/swarm/node.go A swarm node.
Secret api/types/swarm/secret.go Encrypted secret payload.
Config api/types/swarm/config.go Plain-text configuration payload.
Swarm api/types/swarm/swarm.go Cluster-wide config (orchestration, raft, ...).
RuntimeContainerSpec, Networking, Endpoint, UpdateConfig, RestartPolicy, ... Sub-objects

Conversion

API types ↔ SwarmKit protobufs in daemon/cluster/convert/. Each resource has a service.go, task.go, etc. with From* and To* functions.

Lifecycle

graph LR
  Service[Service spec] -->|orchestrator| TaskSpec[Task spec]
  TaskSpec -->|scheduler| Assignment[Node assignment]
  Assignment -->|agent on node| Executor[daemon/cluster/executor]
  Executor --> Container[local container]
  Container -->|state| Agent
  Agent -->|reports| Manager

The orchestrator and scheduler run only on manager nodes. The agent runs on every node and uses Moby's executor to launch tasks as local containers via the container runtime.

Service-level networking

Each service can attach to one or more cluster-scoped networks. The libnetwork controller exposes service VIPs and DNSRR via its embedded resolver. See Networking (libnetwork) and Swarm cluster.

Secrets & configs

Swarm secrets and configs are key-value payloads stored in the manager's Raft DB and mounted into tasks at /run/secrets/<name> (secrets) or arbitrary container paths (configs). They're scoped per-service.

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Service and Task – Moby wiki | Factory