Expand description
Naming and lifecycle of the named container volumes that keep a container-backed resource’s data (an RDS database, an ElastiCache RDB, an EC2 instance’s data dir) across a container being recreated.
A volume belongs to exactly one scope, and its name carries the scope’s tag:
- Data directory (
--storage-mode persistent --data-path <dir>): the tag is a short hash of the canonical--data-pathtogether with a random id minted the first time fakecloud uses the directory and stored in it (SCOPE_FILE). The same data dir reattaches the same volumes across restarts. A different data dir (a copy included, since its path differs), the same path after the directory was wiped (a new id), or a second fakecloud on the same daemon (two containers mounting different host dirs at the same in-container path differ by id) never sees them, so a fresh data dir can’t inherit another one’s database. The volumes are labelled with the scope tag and the data path, sodocker volume ls --filter label=fakecloud-data-path=<dir>finds the ones a data dir owns. - Process (memory mode): nothing outlives the process’s state, so the
tag is unique to the process and the volume carries the
fakecloud-instance=fakecloud-<pid>ownership label the startup reaper uses to remove it once that process is gone.
Volumes created before scoping existed used an unscoped legacy name. A
resource restored from a data dir written by such a build keeps using its
legacy volume (docker has no volume rename, and copying a database between
volumes needs an extra container and can fail half way). Each service
records the choice on the resource as a DataVolumeBinding: resources
created by this build are bound to their scoped volume from the start, and
a resource persisted without a binding is bound once by resolve_binding
against the daemon’s volume list.
Enums§
- Data
Volume Binding - Which data volume a persisted resource mounts.
- Volume
Scope - Which lifetime a fakecloud process’s container volumes are tied to.
Constants§
- DATA_
PATH_ LABEL - Label carrying the canonical
--data-pathof a data-dir scoped volume. - INSTANCE_
LABEL - Ownership label shared with containers and networks (see the reaper).
- SCOPE_
FILE - File in the data dir holding the random half of its volume scope.
- SCOPE_
LABEL - Label carrying the scope tag a volume belongs to.
Functions§
- current_
scope - The scope this process names its volumes in: the data dir once
init_data_dir_scoperan, otherwise the process. - ensure_
volume - Create
namelabelled forscopeunless it already exists (a volume from an earlier run of the same scope, or an adopted legacy volume, is reused as is). Best effort: if the create fails, the container’s-vstill creates the volume, just without labels. - incarnation_
id - A stable incarnation id derived from immutable facts of one resource incarnation (e.g. its ARN and creation timestamp): a delete and a recreate under the same identifier get different ids, so runtime records, container names and data volumes keyed by it never collide.
- init_
data_ dir_ scope - Tie this process’s volumes to
data_path. Called once by the server in persistent mode, before any container runtime is built. A later call returns the scope already in place (it can’t change under volumes already named for it). - is_
scoped_ volume_ name - Whether
nameis a volumescoped_volume_nameproduced forscope_tag. - legacy_
volume_ name - The unscoped name a build before data-dir scoping gave the same volume:
fakecloud-<service>-data-<parts...>. - list_
volumes - Names of every volume on the daemon, or
Nonewhen the CLI can’t answer (so a caller doesn’t mistake an unreachable daemon for “no volumes”). - remove_
process_ volumes - On a clean shutdown in memory mode, remove every volume this process created: its state is gone, so nothing can reattach them. Run after the runtimes stopped their containers (a mounted volume can’t be removed). A no-op for a data-dir scope, whose volumes must outlive the process. A killed process’s volumes are left to the startup reaper instead.
- remove_
volume - Remove a volume, ignoring a missing one.
- resolve_
binding - Bind a resource persisted without a binding (written by a pre-scoping build, or never bound because the daemon couldn’t be listed) against the daemon’s volumes: its scoped volume once that exists (it has been used since), else the legacy volume a pre-scoping build left for it, else a new scoped one.
- sanitize
- Replace characters outside Docker’s
[a-zA-Z0-9_.-]volume-name set. - scoped_
volume_ name fakecloud-<service>-data-<scope tag>-<parts...>.- volume_
exists - Whether the daemon has a volume named
name(false if it can’t answer).