LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

docker-service

manage containerized services in Docker Swarm

TLDR

Create a service
$ docker service create --name [name] [image]
copy
List services
$ docker service ls
copy
Inspect a service
$ docker service inspect [service]
copy
Scale a service
$ docker service scale [service]=[replicas]
copy
Update service image
$ docker service update --image [image]:[tag] [service]
copy
View service logs
$ docker service logs [service]
copy
Remove a service
$ docker service rm [service]
copy

SYNOPSIS

docker service command [options]

DESCRIPTION

docker service manages Swarm services. A service is a declaration of how a set of containers should run across a swarm: image, replica count, networks, mounts, secrets, resource limits, and update strategy. The swarm orchestrator schedules tasks (container instances) on cluster nodes and maintains the desired state, replacing failed tasks and routing traffic via the routing mesh.Service commands are only available on a Docker host participating in a swarm; initialize one with docker swarm init before using them. Updates are applied as rolling updates by default, with rollback available to revert to the previous service spec.

SUBCOMMANDS

create

Create a new service.
ls
List services.
inspect
Display detailed information.
update
Update a service.
scale
Scale services.
logs
Fetch service logs.
ps
List tasks of a service.
rm
Remove services.
rollback
Revert a service to its previous specification.

COMMON OPTIONS

--replicas n (create/scale)

Number of replicated tasks to run.
--mode mode (create)
replicated (default) or global (one task per node).
--publish published:target (create)
Publish a port externally (e.g. `8080:80`).
--network name (create)
Attach the service to a swarm overlay network.
--env, -e KEY=VAL (create/update)
Set environment variables.
--constraint expr (create)
Placement constraints (e.g. `node.role==worker`).
--update-parallelism n / --update-delay dur (create/update)
Rolling-update concurrency and delay between batches.

CAVEATS

Requires swarm mode (docker swarm init / join). For single-host workloads use docker run or docker compose instead. Rolling updates with --update-parallelism 0 will replace all tasks at once and can cause downtime.

SEE ALSO

Copied to clipboard
Kai