Home Explore Blog Models CI



docker

3rd chunk of `content/manuals/engine/swarm/how-swarm-mode-works/services.md`
9f8fc0d50d41bc0d98c3fd5e7c0dd1933dc4163d15738b500000000100000c3a
containers they implement. Hypothetically, you could implement other types of
tasks such as virtual machine tasks or non-containerized process tasks. The
scheduler and orchestrator are agnostic about the type of the task. However, the
current version of Docker only supports container tasks.

The diagram below shows how Swarm mode accepts service create requests and
schedules tasks to worker nodes.

![Services flow](/Users/baehyunsol/Documents/Rust/ragit/sample/docker/content/manuals/engine/swarm/how-swarm-mode-works/../images/service-lifecycle.webp?w=700)

### Pending services

A service may be configured in such a way that no node currently in the
swarm can run its tasks. In this case, the service remains in state `pending`.
Here are a few examples of when a service might remain in state `pending`.

> [!TIP]
> If your only intention is to prevent a service from
> being deployed, scale the service to 0 instead of trying to configure it in
> such a way that it remains in `pending`.

- If all nodes are paused or drained, and you create a service, it is
  pending until a node becomes available. In reality, the first node to become
  available gets all of the tasks, so this is not a good thing to do in a
  production environment.

- You can reserve a specific amount of memory for a service. If no node in the
  swarm has the required amount of memory, the service remains in a pending
  state until a node is available which can run its tasks. If you specify a very
  large value, such as 500 GB, the task stays pending forever, unless you
  really have a node which can satisfy it.

- You can impose placement constraints on the service, and the constraints may
  not be able to be honored at a given time.

This behavior illustrates that the requirements and configuration of your tasks
are not tightly tied to the current state of the swarm. As the administrator of
a swarm, you declare the desired state of your swarm, and the manager works with
the nodes in the swarm to create that state. You do not need to micro-manage the
tasks on the swarm.

## Replicated and global services

There are two types of service deployments, replicated and global.

For a replicated service, you specify the number of identical tasks you want to
run. For example, you decide to deploy an HTTP service with three replicas, each
serving the same content.

A global service is a service that runs one task on every node. There is no
pre-specified number of tasks. Each time you add a node to the swarm, the
orchestrator creates a task and the scheduler assigns the task to the new node.
Good candidates for global services are monitoring agents, anti-virus scanners
or other types of containers that you want to run on every node in the swarm.

The diagram below shows a three-service replica in gray and a global service
in black.

![Global vs replicated services](/Users/baehyunsol/Documents/Rust/ragit/sample/docker/content/manuals/engine/swarm/how-swarm-mode-works/../images/replicated-vs-global.webp?w=450)

## Learn more

* Read about how Swarm mode [nodes](nodes.md) work.
* Learn how [PKI](pki.md) works in Swarm mode.

Title: Pending Services and Replicated vs. Global Services in Docker Swarm
Summary
This section discusses pending services in Docker Swarm, which occur when no node can run a service's tasks due to reasons like paused nodes, insufficient memory, or unmet placement constraints. It advises scaling services to 0 instead of relying on the 'pending' state to prevent deployment. The section then differentiates between replicated services, where a specific number of identical tasks run, and global services, which run one task on every node in the swarm, suitable for monitoring agents or anti-virus scanners.