Compose file
dicer compose reads a project from a YAML file: its services, and the networks and volumes they use. A key it does not support is refused, with the reason, rather than ignored. dicer compose config checks a file and shows it as it is read. See Compose for a walk through one.
The file
dicer compose looks for dicer-compose.yaml, dicer-compose.yml, compose.yaml and compose.yml, in that order, in the current directory and then in each directory above it. -f or $DICER_COMPOSE_FILE names another. Keys starting x- are extensions: ignored, and where YAML anchors are defined to share settings between services.
Names
A project’s instances are named PROJECT-SERVICE, and its networks and volumes PROJECT-NAME, so each belongs visibly to its project and two projects on a host do not collide. Names are letters, digits and hyphens: db_primary cannot be a service’s name.
Each instance is labelled dicer.compose.project and dicer.compose.service, which is how dicer compose finds its instances again, and dicer.compose.config-hash, a digest of its definition, which is how dicer compose up tells a changed service from one it can leave running. Labels starting dicer.compose. are reserved for dicer compose.
General
The project’s own keys. The sections after them are its services, networks and volumes.
name
string
name is the project’s name. -p or $DICER_COMPOSE_PROJECT_NAME overrides it. Unset is the file’s directory’s name, in lower case.
version
string
version is accepted and ignored: it is Docker Compose’s, and obsolete.
services.*
mapping of names to mappings
services are the project’s services, by name. Each is one instance. Required.
services.*.image
string
image is the image to boot. Required.
services.*.container_name
string
container_name is the instance’s name, instead of PROJECT-SERVICE. Changing it replaces the instance at the next dicer compose up.
services.*.hostname
string
hostname is the guest’s hostname, which other instances on its network can look it up by. Unset is the service’s name.
services.*.command
string, or list of strings
command is the command to run: a list, or a string split as a shell would split it. It replaces the image’s ENTRYPOINT and CMD, as the command given to dicer run does.
services.*.entrypoint
string, or list of strings
entrypoint is put before command, and together they replace the image’s ENTRYPOINT and CMD.
services.*.user
string
user is who the command runs as: user, uid, user:group or uid:gid, as dicer run --user. Unset is the image’s USER, or root if it has none.
services.*.environment
mapping of strings, or list of KEY=VALUE strings
environment is the variables the command runs with. A KEY with no value takes this shell’s, and is left out if it has none.
services.*.env_file
string, or list of strings
env_file is files of KEY=VALUE lines, read in order, relative to the project directory. environment wins over them.
services.*.labels
mapping of strings, or list of KEY=VALUE strings
labels are the instance’s labels. Those starting dicer.compose. are dicer compose’s own.
services.*.tmpfs
string, or list of strings
tmpfs is the paths to mount an empty tmpfs at. A tmpfs takes no options.
services.*.networks
list of one name, or mapping of one name to a mapping
networks is the network the instance joins: a list of one name, or a mapping of one name to its settings, which can give the instance a fixed address. Unset is the file’s network called default, which the project has whether the file declares it or not: PROJECT-default. On its network, a service is found by its hostname, which is its name unless it says otherwise, and by its instance’s name.
networks:
backend:
ipv4_address: 172.30.0.10services.*.depends_on
list of names, or mapping of names to mappings
depends_on is the services to start first: a list of them, or a mapping of them to the condition to wait for. service_started, the default, waits until the service is running; service_healthy until it is healthy, for which it must have a health check, of its own or its image’s; and service_completed_successfully until it has ended with exit code 0. A service is not started if one it depends on fails to come up, is unhealthy or ends with another code, and services that depend on each other in a cycle are refused.
depends_on:
db:
condition: service_healthyservices.*.restart
string
restart is no, always, unless-stopped, on-failure or on-failure:N: see Restarts. Unset is no.
services.*.cpus
number
cpus is taken for vcpus, if it is a whole number.
services.*.vcpus
integer
vcpus is the machine’s vCPUs, as dicer run --vcpus. Unset is 1.
services.*.mem_limit
size, such as 512MiB or 2GiB
mem_limit is taken for memory.
services.*.memory
size, such as 512MiB or 2GiB
memory is the machine’s memory, as dicer run --memory. Unset is 512MiB.
services.*.max_vcpus
integer
max_vcpus is the most vCPUs dicer resize can give the running instance, on Cloud Hypervisor on x86_64, as dicer run --max-vcpus. Unset is none.
services.*.max_memory
size, such as 512MiB or 2GiB
max_memory is the most memory dicer resize can give the running instance, as dicer run --max-memory. Unset is none.
services.*.disk
size, such as 512MiB or 2GiB
disk is the size of the instance’s disk, as dicer run --disk. Unset is 10GiB.
services.*.disk_rate
size per second, such as 50MiB or 50MiB/s
disk_rate is the bytes per second each of the instance’s disks can be read and written at, as dicer run --disk-rate. Unset is unlimited.
services.*.disk_iops
integer
disk_iops is the operations per second each of the instance’s disks can be read and written at, as dicer run --disk-iops. Unset is unlimited.
services.*.standby_after
duration, such as 30s or 5m
standby_after is how long the instance may be idle before it is put on standby, as dicer run --standby-after, e.g. 15m. Unset is never.
services.*.upload_rate
size per second, such as 50MiB or 50MiB/s
upload_rate is the bytes per second the instance can send, as dicer run --upload-rate. Unset is unlimited.
services.*.download_rate
size per second, such as 50MiB or 50MiB/s
download_rate is the bytes per second the instance can receive, as dicer run --download-rate. Unset is unlimited.
services.*.kernel
string
kernel is the kernel to boot, as dicer run --kernel. Unset is the daemon’s default.
services.*.kernel_args
string
kernel_args is kernel command line arguments, as dicer run --kernel-args.
services.*.hypervisor
string
hypervisor is cloud-hypervisor or firecracker, as dicer run --hypervisor-type. Unset is cloud-hypervisor.
services.*.hypervisor_version
string
hypervisor_version is a version of the hypervisor the daemon ships, as dicer run --hypervisor-version. Unset is the hypervisor’s default version, which dicer info shows.
services.*.init_mode
string
init_mode is auto, exec or systemd, as dicer run --init-mode: see Init modes. Unset is auto.
services.*.ports[]
list of strings or mappings
ports are the ports to publish on the host, each as [HOST_IP:]HOST_PORT:GUEST_PORT[/tcp|udp], as dicer run -p takes it, or as a mapping. An IPv6 host address goes in brackets: [::1]:8080:80. A port must be published on a port of the host: "80" alone is refused, as are ranges.
services.*.ports[].target
integer
target is the guest’s port. Required.
services.*.ports[].published
string
published is the host’s port. Required.
services.*.ports[].host_ip
string
host_ip is the host’s address to publish on. Unset is every address.
services.*.ports[].protocol
string
protocol is tcp or udp. Unset is tcp.
services.*.ports[].mode
string
mode is accepted and ignored: it is Docker Swarm’s.
services.*.volumes[]
list of strings or mappings
volumes are the volumes, files and directories to mount, each as SOURCE:TARGET[:ro] or as a mapping. A SOURCE that is a name is a volume, which must be declared under the file’s volumes. One starting /, . or ~ is a path, relative to the project directory. A file on the machine running dicer compose is read when the project is loaded and sent to the daemon, which puts it in the guest each time the instance starts, as with dicer run --mount type=file. A changed file changes the service’s definition, so dicer compose up recreates its instance. A directory is shared from the daemon’s host while the guest runs, as with --mount type=directory: it must be one the daemon allows, and needs Cloud Hypervisor. A path that is a directory on this machine is taken to be one on the daemon’s host. With a remote daemon, give a directory in the long form, with type: directory. A TARGET alone, an anonymous volume, is refused: name the volume.
services.*.volumes[].type
string
type is volume; bind, for a file or a directory, whichever the path is on the machine running dicer compose; directory, for a directory on the daemon’s host; or tmpfs. Required.
services.*.volumes[].source
string
source is the volume’s name, the file’s path on the machine running dicer compose, or the directory’s path on the daemon’s host. A tmpfs has none.
services.*.volumes[].target
string
target is the path in the guest. Required.
services.*.volumes[].read_only
boolean
read_only mounts it read-only.
services.*.healthcheck
mapping
healthcheck is how the workload’s health is checked: see Health checks.
services.*.healthcheck.test
string, or list of strings
test is a command to check health with: ["CMD", ARG...] runs a command; ["CMD-SHELL", LINE], or a string, runs a line with /bin/sh; ["NONE"] checks nothing, not even as the image says to.
services.*.healthcheck.http
string
http is PORT[/path]: healthy when a GET in the guest answers 2xx or 3xx. It suits an image with no shell.
services.*.healthcheck.tcp
integer
tcp is a port: healthy when a connection to it in the guest is accepted. It suits an image with no shell.
services.*.healthcheck.interval
duration, such as 30s or 5m
interval is the time between checks. Unset is 10s.
services.*.healthcheck.timeout
duration, such as 30s or 5m
timeout is the time a check may take. Unset is 5s.
services.*.healthcheck.start_period
duration, such as 30s or 5m
start_period is the time after a start in which failed checks do not count.
services.*.healthcheck.retries
integer
retries is how many failed checks in a row make the instance unhealthy. Unset is 3.
services.*.healthcheck.disable
boolean
disable checks nothing, as test: ["NONE"] does.
networks.*
mapping of names to mappings
networks are the networks the services join, by name.
networks.*.name
string
name is the daemon’s name for the network, instead of PROJECT-NAME.
networks.*.external
boolean
external uses a network that already exists, named by the key or name, and never creates or deletes it. It takes no other settings.
networks.*.subnet
string
subnet is the network’s subnet, such as 172.30.0.0/24. Unset is a free /24 of 10.213.0.0/16, picked by dicer compose up.
networks.*.gateway
string
gateway is the network’s gateway. Unset is the subnet’s first address.
networks.*.mtu
integer
mtu is the network’s MTU. Unset is 1500.
networks.*.nameservers
string, or list of strings
nameservers are the nameservers the network’s instances use. Unset is 8.8.8.8.
networks.*.isolated
boolean
isolated stops the network’s instances reaching each other.
networks.*.internal
boolean
internal stops the network’s instances reaching anything beyond it: the outside, other networks, the host and upstream nameservers. It takes no nameservers.
networks.*.ipam
mapping
ipam is another way of giving subnet and gateway, as Docker Compose does, with one entry.
ipam:
config:
- subnet: 172.30.0.0/24networks.*.ipam.config[]
list of mappings
config is the network’s addresses: one entry.
networks.*.ipam.config[].subnet
string
subnet is the network’s subnet.
networks.*.ipam.config[].gateway
string
gateway is the network’s gateway.
volumes.*
mapping of names to mappings
volumes are the volumes the services mount, by name. A volume may be declared with nothing:
volumes:
data:volumes.*.name
string
name is the daemon’s name for the volume, instead of PROJECT-NAME.
volumes.*.external
boolean
external uses a volume that already exists, named by the key or name, and never creates or deletes it.
volumes.*.size
size, such as 512MiB or 2GiB
size is the volume’s size. Unset is 10GiB.
Variables
Values, not keys, may hold variables, which are taken from the environment, then from .env in the project directory, or the file --env-file names:
| Written | Is |
|---|---|
$VAR, ${VAR} | The value, or nothing if it is not set. |
${VAR:-default} | default if VAR is not set or is empty. |
${VAR-default} | default if VAR is not set. |
${VAR:?message} | Fails, saying message, if VAR is not set or is empty. |
${VAR?message} | Fails if VAR is not set. |
${VAR:+other} | other if VAR is set and not empty, otherwise nothing. |
${VAR+other} | other if VAR is set, otherwise nothing. |
$$ | A $. |
A default, message or other may hold variables itself: ${PORT:-${DEFAULT_PORT}}.
An unquoted value takes the type of what it becomes, so cpus: ${CPUS:-2} is a number and external: ${EXTERNAL:-true} a boolean. A quoted one, "${CPUS}", is always a string.
dicer compose config shows variables as they are written, not their values, though it substitutes them to check the file; --interpolate shows the values. The values reach the daemon all the same: an instance’s environment is part of its definition, which dicer inspect shows to anyone who can use the daemon.
Not supported
These keys of a service are refused, saying why, as are secrets and configs at the top of the file. Most describe what a virtual machine already has, such as its isolation from the host, or something Dicer has no counterpart of.
| Key | Why |
|---|---|
build | Dicer boots images from a registry: build and push the image, then name it with image. |
cap_add | A guest is a whole machine, and its workload already has it to itself. |
cap_drop | A guest is a whole machine, and its workload already has it to itself. |
configs | Mount the config’s file with volumes instead. |
deploy | Set vcpus, memory and disk on the service instead. |
devices | Instances cannot be given host devices. |
dns | Set nameservers on the network instead. |
expose | Every port is open on the instance’s network already. |
extends | Use YAML anchors and x- extensions to share settings. |
extra_hosts | An instance’s /etc/hosts cannot be added to. |
init | dicer-init is always the guest’s first process; see init_mode. |
links | Services on a network find each other by name already. |
logging | The guest’s console is kept with the instance: see dicer compose logs. |
network_mode | An instance joins one network, named with networks. |
platform | An instance runs on the host’s architecture. |
privileged | A guest is a whole machine, and its workload already has it to itself. |
profiles | Every service in the file is part of the project. |
pull_policy | Use dicer compose up --pull instead. |
scale | Each service is one instance. |
secrets | Mount the secret’s file with volumes instead. |
shm_size | Mount a tmpfs at /dev/shm instead. |
stdin_open | Attach with dicer compose exec instead. |
stop_signal | A stop shuts the guest down. |
sysctls | Set kernel parameters in the guest, or with kernel_args. |
tty | Attach with dicer compose exec instead. |
ulimits | Set limits in the guest’s own configuration. |
working_dir | The image’s working directory is used. |