Docker Service
The Docker service runs Docker Engine in a dedicated virtual machine (VM). Use it for software that ships as a Docker image or a Docker Compose stack. A VM boots slower than a container and its resources don't scale automatically, so your own code is usually better served by a native runtime service. See Containers vs VMs for the difference.
Quick Start
Create the service with a zerops-import.yaml:
Then deploy a zerops.yaml that pulls the image and runs it:
The Docker recipe repository has a complete example.
Resources and Scaling
A Docker service doesn't scale automatically, neither its resources nor its number of VMs.
| Topic | Behavior |
|---|---|
| Resources | Fixed values for cpu, ram and disk in verticalAutoscaling, no min-max ranges. Without them a new service gets 1 vCPU, 1 GB RAM and 5 GB disk. |
| Changing resources | Every change restarts the VM. |
| Disk | Can be increased, never decreased. |
| Number of VMs | The service runs minContainers VMs. With one VM, the service is unavailable during maintenance of its server. |
Building and Preparing Images
The build phase runs in a regular container without Docker, so images can't be built or pulled there.
It can still prepare files for the VM, such as a docker-compose.yaml.
Pull or build images in run.prepareCommands.
Zerops caches the result and reuses it on later deploys until the commands or the addToRunPrepare files change.
Always use specific version tags (like 1.0.0) instead of :latest.
Because of the cache, a new :latest image isn't pulled on later deploys.
Building from a Dockerfile
To build your own image without a registry, copy the Dockerfile and its build context to the prepare phase with addToRunPrepare and run docker build there:
A change to any file in addToRunPrepare invalidates the cache, so every deploy with new code builds the image again.
Private Registries
Store the registry credentials as secret variables and log in before pulling:
Running Containers
Network
Run containers with --network=host (network_mode: host in Docker Compose).
The container then listens directly on the VM's ports, and you expose them with ports in zerops.yaml.
Docker's own port publishing (-p) is not needed.
Container Lifecycle
Zerops runs the start command in the foreground and restarts it whenever it exits.
Its output goes to the runtime log.
Don't detach with -d: the command exits right away, Zerops starts it again, and every restart creates another container.
Each docker run creates a new container, and Docker keeps exited containers on the VM disk, also across VM restarts.
Always pass --rm so Docker removes the container when it exits.
Without --rm, an app that crashes in a loop leaves thousands of stopped containers behind.
The Docker daemon can then run out of memory while loading them on startup, and the VM fails its readiness check.
To recover, stop the service, raise the RAM and start the service again. Then run docker container prune -f and lower the RAM.
Don't use --name without --rm. The next restart fails because the name is already in use, and the app doesn't come back.
Don't add --restart, Docker rejects it together with --rm.
Environment Variables
Variables from run.envVariables and the service's environment variables are set for the start command, not inside your containers.
Pass each one with -e (or list them under environment in Docker Compose):
Docker Compose
Deploy the docker-compose.yaml and make it available to prepareCommands with addToRunPrepare:
To run only some services of the file, name them: docker compose pull api and docker compose up api --force-recreate.
Docker Compose keeps one container per service across up runs, so stopped containers don't accumulate.
docker compose up exits only when all its containers stop, so a single crashed service stays down.
Set restart: unless-stopped on the services that Docker should restart.
Deploys and Data
A deploy creates new VMs, and the old ones keep serving traffic until the new ones are ready, see Subsequent deploys. Add a readiness check so that Zerops switches traffic only when your container accepts requests.
VMs are ephemeral like containers. Data on the VM disk, including Docker volumes, is lost when a deploy replaces the VM. Keep persistent data in a database or storage service.
Debugging
Connect to a VM over SSH and inspect it with the Docker CLI:
The runtime log also keeps the output of containers that --rm already removed.
Supported Versions
- 26.1