The 'No such service' error occurs when Docker Swarm cannot find a service matching the name you specified. This typically happens when the service was never deployed, has been removed, or you're running commands against a non-swarm node. Verify the service exists with docker service ls.
The "Error: No such service" message in Docker Swarm indicates that the Docker daemon cannot locate a service matching the name or ID you provided in your command. Docker Swarm maintains a registry of all services deployed to the cluster. When you issue commands like `docker service ps myservice`, `docker service logs myservice`, or `docker service rm myservice`, Swarm searches for a service with that exact name. If no match is found, it returns this error. This error can also occur in Docker Compose (v2+) contexts, particularly with certain command combinations or version-specific regressions. However, in the Swarm context, it simply means the service doesn't exist in the current swarm cluster.
First, check what services are currently deployed in your swarm:
# List all services in the swarm
docker service ls
# Filter by name pattern
docker service ls --filter "name=myservice"
# Show detailed output
docker service ls --format "table {{.ID}}\t{{.Name}}\t{{.Mode}}\t{{.Replicas}}"If your service doesn't appear in the list, it either wasn't deployed or has been removed.
Docker service commands must be run on a manager node. Check your node status:
# Check if this node is in swarm mode
docker info | grep -i swarm
# Check if this is a manager node
docker node ls
# If you see "This node is not a swarm manager", you need to:
# 1. SSH to a manager node, or
# 2. Initialize swarm if not done: docker swarm initWorker nodes cannot run service management commands. You'll get "This node is not a swarm manager" before "No such service" if running on a worker.
When you deploy services via docker stack deploy, the stack name becomes a prefix:
# Deploying with stack
docker stack deploy -c docker-compose.yml mystack
# Service "web" becomes "mystack_web"
docker service ls
# NAME MODE REPLICAS IMAGE
# mystack_web replicated 3/3 nginx:latest
# Use the full name with prefix
docker service ps mystack_web
# Or list services in a specific stack
docker stack services mystackAlways use the full service name including the stack prefix when using docker service commands.
If the service doesn't exist, you need to create it:
# Create a simple service
docker service create --name myservice nginx
# Create with replicas
docker service create --name myservice --replicas 3 nginx
# Deploy from a compose file
docker stack deploy -c docker-compose.yml mystack
# Or using docker-compose in swarm mode
docker compose up -dAfter creation, verify with docker service ls to confirm the service exists.
If you manage multiple swarm clusters, ensure you're targeting the correct one:
# List all Docker contexts
docker context ls
# See which context is active (marked with *)
docker context show
# Switch to a different context
docker context use production-swarm
# Or specify context for a single command
docker --context production-swarm service lsServices created in one cluster won't be visible when connected to a different cluster.
Sometimes stack deployments fail silently. Check for deployment issues:
# List all stacks
docker stack ls
# Check services in a stack
docker stack services mystack
# View detailed task information (shows failures)
docker stack ps mystack --no-trunc
# Check for failed tasks
docker stack ps mystack --filter "desired-state=shutdown"
# Get detailed error messages
docker service ps myservice --no-trunc --filter "desired-state=shutdown"Look for tasks in "Rejected" or "Failed" state to understand why the service didn't start.
Docker Compose v2.3+ has known issues with "No such service" errors in certain scenarios:
# Check your compose version
docker compose version
# Known issues occur with:
# - --no-deps flag with healthcheck dependencies
# - Services with profiles
# - Multiple compose files
# Workarounds:
# 1. Remove --no-deps if using service dependencies
docker compose up myservice # instead of docker compose up --no-deps myservice
# 2. Explicitly specify profile when restarting
docker compose --profile myprofile restart myservice
# 3. Update to latest Docker Compose version
docker compose version
# Consider updating if below 2.20These are typically version-specific regressions that get fixed in later releases.
### Understanding Swarm Service Discovery
In Docker Swarm, services are cluster-wide objects managed by the swarm manager. Unlike standalone containers, services:
- Are only visible on manager nodes via docker service commands
- Have names that are cluster-unique (no two services can have the same name)
- Are automatically load-balanced across replicas
- Persist their definition in the Raft consensus store
# Service is visible via swarm commands
docker service ls
docker service inspect myservice
# Individual containers (tasks) are visible on all nodes
docker ps # Shows containers on current node only### Difference Between Containers and Services
A common source of confusion:
# These are different things:
docker ps # Lists containers (local to this node)
docker service ls # Lists services (cluster-wide)
# A service named "web" creates containers like:
# web.1.abc123 (on node1)
# web.2.def456 (on node2)
# You can docker exec into the container, not the service:
docker exec -it web.1.abc123 bash # Works
docker exec -it web bash # Doesn't work### Service Inspection and Debugging
For detailed troubleshooting:
# Get service configuration
docker service inspect myservice --pretty
# Check why tasks failed
docker service ps myservice --no-trunc
# Get logs from all service replicas
docker service logs myservice
# Follow logs in real-time
docker service logs -f myservice
# Get logs from a specific task
docker service logs myservice.1### Global vs Replicated Services
Services can run in different modes:
# Replicated: specific number of instances (default)
docker service create --replicas 3 --name web nginx
# Global: one instance per swarm node
docker service create --mode global --name monitoring prometheus
# The mode affects how you reference and scale services
docker service scale web=5 # Only works for replicated mode### Handling Rolling Updates to Non-Existent Services
When automating deployments, always check if the service exists first:
# Check if service exists before updating
if docker service inspect myservice > /dev/null 2>&1; then
docker service update --image nginx:latest myservice
else
docker service create --name myservice nginx:latest
fi
# Or use docker stack deploy which handles both create and update
docker stack deploy -c docker-compose.yml mystack### Swarm Service vs Docker Compose Service
The term "service" has different meanings:
| Context | Definition | Commands |
|---------|------------|----------|
| Swarm | Cluster-wide service definition | docker service |
| Compose | Service defined in compose file | docker compose |
| Compose on Swarm | Compose service deployed to swarm | docker stack |
When you docker stack deploy, compose services become swarm services with stack name prefixes.
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec