LinuxCommandLibrary

docker-service

Manage Docker services

TLDR

List the services on a Docker daemon

$ docker service ls
copy

Create a new service
$ docker service create --name [service_name] [image]:[tag]
copy

Display detailed information about one or more services
$ docker service inspect [service_name_or_ID1 service_name_or_ID2]
copy

List the tasks of one or more services
$ docker service ps [service_name_or_ID1 service_name_or_ID2 ...]
copy

Scale to a specific number of replicas for a space-separated list of services
$ docker service scale [service_name]=[count_of_replicas]
copy

Remove one or more services
$ docker service rm [service_name_or_ID1 service_name_or_ID2]
copy

SYNOPSIS

docker service [OPTIONS] COMMAND [ARG...]
Commands: create, inspect, logs, ls, ps, rm, scale, update

PARAMETERS

--format string
    Pretty-print services using a Go template

--help
    Print usage

--quiet
    Only display service IDs

DESCRIPTION

The docker service command manages services in a Docker swarm cluster, defining the desired state for containers across manager and worker nodes.

A service specifies an image, replicas, networks, and constraints. Swarm orchestrates tasks (container instances) to match this state, handling scaling, failures, and rolling updates.

Key uses include deploying replicated services (multiple identical tasks) or global services (one task per node). Commands enable creation, listing, inspection, scaling, updating, and removal.

Requires an initialized swarm (docker swarm init or docker swarm join). Services run only in swarm mode, not standalone Docker.

Example: docker service create --replicas 3 --name web nginx deploys 3 Nginx tasks.

Integrates with Docker Compose via docker stack deploy for multi-service apps. Provides load balancing, service discovery, and secrets/config management.

CAVEATS

Requires Docker swarm mode initialized; services ignore standalone mode. Manager nodes handle orchestration; use docker node ls to check cluster status.

DEPLOYMENT WORKFLOW

1. Init swarm: docker swarm init
2. Create service: docker service create --name app --replicas 2 nginx
3. Scale: docker service scale app=5
4. Update: docker service update --image nginx:alpine app

SERVICE TYPES

Replicated: Fixed tasks (default).
Global: One task per node (--mode global).

HISTORY

Introduced in Docker 1.12 (July 2016) with Swarm mode v1.12, replacing deprecated Docker Swarm (v1). Evolved with SwarmKit for advanced orchestration; current in Docker 27+.

SEE ALSO

docker-swarm(1), docker-node(1), docker-stack(1), docker-task(1)

Copied to clipboard