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

Available Commands:
  create      Create a new service
  inspect     Display detailed information on one or more services
  logs        Fetch the logs of a service or task
  ls          List services
  ps          List the tasks of one or more services
  rm          Remove one or more services
  rollback    Rollback changes to a service's configuration
  scale      Scale one or multiple replicated services
  update     Update a service

Run `docker service COMMAND --help` for more information on a specific subcommand.

PARAMETERS

--help
    Displays help information for the `docker service` command or its subcommands (e.g., `docker service create --help`).

-D, --debug
    Enable debug mode. Provides more verbose output for troubleshooting. This is a global Docker option that can precede `service`.

-H, --host
    Daemon socket(s) to connect to. Specifies the Docker daemon to communicate with. This is a global Docker option.

-v, --version
    Print the Docker version information and exit. This is a global Docker option.

[SUBCOMMAND OPTIONS]
    Each `docker service` subcommand (e.g., `create`, `update`, `scale`) has its own extensive set of specific options. Refer to `docker service COMMAND --help` for details on each subcommand's parameters.

DESCRIPTION

The `docker service` command is a core component of Docker Swarm Mode, enabling the management of applications as distributed services across a cluster of Docker engines. It allows users to define desired states for applications, including the number of replicas, attached networks, exposed ports, and mount volumes. Docker Swarm then ensures that the service maintains this desired state, handling task scheduling, load balancing, and self-healing in case of node failures.

Services are the fundamental building blocks for orchestrating fault-tolerant, scalable, and highly available applications in a Swarm cluster. This command provides subcommands for creating, listing, inspecting, updating, scaling, and removing services, making it central to deploying and operating containerized applications in a production environment.

CAVEATS

`docker service` commands are only available when Docker is running in Swarm Mode. If Swarm Mode is not initialized or joined on the Docker daemon, these commands will fail with an error. Managing stateful applications (e.g., databases) in Docker Swarm requires careful consideration of data persistence and distributed storage solutions, as services themselves are inherently stateless. While services abstract away individual containers (tasks), troubleshooting often requires inspecting individual tasks and their logs. The overlay network must be properly configured for services to communicate across different nodes in the Swarm.

SERVICE TYPES

Docker services can be deployed as replicated services, where a specified number of identical tasks are run across the Swarm, or as global services, where one task is run on every available node in the Swarm. Replicated services are ideal for scaling applications, while global services are often used for monitoring agents or logging collectors.

ROLLING UPDATES

The `docker service update` command supports rolling updates, allowing you to deploy new versions of a service without downtime. You can configure update parameters like parallelism (how many tasks to update concurrently), delay between updates, and rollback conditions, ensuring a smooth transition for your applications.

LOAD BALANCING

Docker Swarm provides built-in DNS-based load balancing for services. When a service is created, Swarm assigns it a virtual IP (VIP) and DNS entry. Requests to the service name are load-balanced across all healthy tasks of that service, distributing traffic automatically.

HISTORY

Docker Swarm Mode, including the `docker service` command, was introduced with Docker Engine 1.12 in June 2016. This release marked a significant shift by integrating native orchestration capabilities directly into the Docker CLI, making it much easier for users to set up and manage container clusters without external tools. Prior to this, Docker had a standalone `Docker Swarm` project, which was separate and less integrated. The integrated Swarm Mode aimed to provide a simpler, more opinionated orchestration solution compared to Kubernetes, focusing on ease of use for smaller to medium-sized deployments and immediate integration with the Docker ecosystem. Subsequent releases have introduced further enhancements to service capabilities, such as secret management, configuration management, and improved rolling updates.

SEE ALSO

docker(1), docker swarm(1), docker stack(1), docker container(1), docker network(1)

Copied to clipboard