What is a Service?
A service in Uncloud is a logical grouping of containers running the same image. Services are the unit of deployment and scaling. Services define:- Container image and configuration
- Number of replicas (for replicated services)
- Environment variables, volumes, and ports
- Health checks and update behavior
- Placement constraints
Uncloud uses the familiar Docker Compose format for defining services, so you can reuse existing compose files with minimal changes.
Service Modes
Uncloud supports two deployment modes for services:Replicated Mode
In replicated mode, you specify exactly how many container replicas to run. Uncloud distributes these replicas across available machines based on placement constraints.- Application services that can scale horizontally
- Stateless web servers and APIs
- Worker processes that handle background jobs
- Services where you want explicit control over replica count
Global Mode
In global mode, Uncloud runs exactly one container on every machine in the cluster. When you add a new machine, a container automatically starts there.- Reverse proxies and load balancers (like Caddy)
- Monitoring and logging agents
- Network utilities that need to run everywhere
- Infrastructure services
Container Lifecycle
Uncloud manages the complete lifecycle of containers in a service:Starting Containers
When you deploy a service:- Image pull - Uncloud pulls the image according to the pull policy
- Machine selection - Target machines are chosen based on placement constraints
- Container creation - Containers are created with the specified configuration
- Network attachment - Containers join the Docker bridge network and get IPs
- State update - Container info is stored in cluster state
- DNS registration - Service names become resolvable
Running Containers
Once running, containers:- Get cluster-unique IP addresses from the machine’s subnet
- Can communicate with any other container via the mesh network
- Are monitored by Docker’s restart policy
- Report health status if health checks are configured
Docker on each machine ensures containers restart on failures according to the restart policy. However, containers won’t automatically move to other machines if a machine fails.
Updating Containers
When you update a service (new image, config change, etc.):- Change detection - Uncloud compares new spec with existing containers
- Rolling update - Containers are updated one at a time
- Health monitoring - Each new container must become healthy before continuing
- Cleanup - Old containers are removed after successful updates
Stopping Containers
When you remove a service:- SIGTERM - Containers receive graceful shutdown signal
- Grace period - Wait for configured stop grace period (default 10s)
- SIGKILL - Force kill if container hasn’t stopped
- Network cleanup - IPs are released back to the pool
- State update - Service and container records are removed
- DNS cleanup - Service names are unregistered
Service Discovery via DNS
Every machine runs an internal DNS server (part ofuncloudd) that resolves service names to container IPs.
DNS Naming
Services are accessible via these DNS names:| DNS Name | Resolves To |
|---|---|
service-name.internal | All container IPs for the service |
rr.service-name.internal | Round-robin through all containers |
nearest.service-name.internal | Local containers first, then remote |
machine-name.machine.internal | The machine’s mesh IP |
The
.internal domain is reserved for cluster-internal service discovery. External DNS queries are forwarded to upstream DNS servers.Resolution Modes
The DNS server supports multiple resolution modes:Default (Round-Robin)
Nearest
Explicit Round-Robin
Example Usage
Here’s how services discover each other:web service can reach api using api.internal without knowing specific container IPs.
DNS queries are resolved with 0 TTL by default, ensuring clients always get current container IPs. This may be increased to allow some caching in the future.
Health Checks
Uncloud supports Docker-native health checks to monitor container health.Defining Health Checks
Health Check Behavior
- During deployment - New containers must become healthy before old ones are stopped
- During updates - Uncloud waits for health checks to pass before continuing to next container
- At runtime - Docker monitors health and can restart unhealthy containers
If a health check is defined, Uncloud waits for it to pass during deployments. Without a health check, Uncloud only verifies the container started successfully.
Health Check States
Containers can be in these health states:- starting - Container is in the start period, failures don’t count yet
- healthy - Health check is passing
- unhealthy - Health check failed more than the retry count
uc ps or docker ps on individual machines.
Update Configuration
Control how services are updated with theupdate_config section:
Update Order
start-first (default for stateless services):- Starts the new container before stopping the old one
- Minimizes downtime
- Briefly runs both containers simultaneously
- Stops the old container before starting the new one
- Prevents data corruption for stateful services
- Causes brief downtime during updates
Monitor Period
Themonitor field specifies how long to wait after starting a container before considering it stable:
- Containers with health checks: Succeed early if they become healthy
- Containers without health checks: Wait full monitor period
- Default is 10 seconds if not specified
Pull Policies
Control when images are pulled from registries:- missing (default) - Pull only if image is not on the target machine
- always - Always pull the latest version from registry
- never - Never pull, fail if image is not available locally
Environment Variables
Define environment variables for containers:Resource Limits
Set resource constraints for containers:Resource limits are enforced by Docker on each machine. Uncloud does not currently perform bin-packing or resource-aware scheduling.
Listing Services
View all running services:- Service name and ID
- Mode (replicated or global)
- Number of containers
- Images in use
- Exposed endpoints
Removing Services
Remove a service and all its containers:Further Reading
Networking
Learn how containers communicate across machines
Storage
Use volumes for persistent data
Ingress
Expose services to the internet
Deploying Services
Practical guide to service deployment
