English

Developer tools · Docker run to Docker compose converter

Volumes in docker run vs Compose: bind mounts, named volumes and :ro

· How it works

docker compose volumes

Abstract diagram illustrating volumes in docker run vs compose: bind mounts, named volumes and :ro
Original ToolAcre vector illustration

The -v flag can mean three different things depending on what is left of the colon. This post explains bind mounts, named volumes and anonymous volumes, and how each becomes YAML.

The database came back empty — the container was recreated and the -v flag never referred to a place on disk that survives

The database came back empty — the container was recreated and the -v flag never referred to a place on disk that survives. Evidence: a target-only -v value is anonymous and receives a persistence warning. Reproduce volume persistence with disposable literals. Pair each source occurrence with service volumes and named declarations; reserve source classification and paths for destination review.

The volumes incident also reveals that A separate volumes incident boundary is that --mount is consumed correctly but reported as unsupported. Evidence: --mount is consumed correctly but reported as unsupported. This volume persistence constraint is a stopping point. Inspect service volumes and named declarations without manufacturing behavior, then document a host check for source classification and paths.

Three meanings of -v — an absolute path (bind mount), a name (named volume) or nothing before the colon (anonymous volume)

Three meanings of -v — an absolute path (bind mount), a name (named volume) or nothing before the colon (anonymous volume). Evidence: simple names, host paths, relative paths, variables and Windows drives are classified differently. Trace volume persistence tokens into service volumes and named declarations. Separate ordered values from last-value fields; source classification and paths is outside collection.

A related volumes mechanism boundary is that A separate volumes grammar boundary is that both pgdata and the read-only init bind remain literal volume strings. Evidence: both pgdata and the read-only init bind remain literal volume strings. Use this volume persistence fact to predict one member or scalar in service volumes and named declarations. Check warnings before deciding anything about source classification and paths.

Named volumes need a declaration — the top-level volumes: key that Compose requires, and what happens when it is missing

Named volumes need a declaration — the top-level volumes: key that Compose requires, and what happens when it is missing. Evidence: named sources gain null declarations in top-level volumes. Judge volume persistence serialization from its model. Quoting in service volumes and named declarations protects types but gives no operational proof for source classification and paths.

The second volumes serialization observation is A separate volumes output boundary is that relative strings are preserved without resolving a future Compose directory. Evidence: relative strings are preserved without resolving a future Compose directory. This volume persistence output separates settings from unavailable context. Keep service volumes and named declarations reviewable and check source classification and paths independently.

The converter preserves -v short syntax and warns that --mount must be translated by hand

Options after the second colon — ro, z and Z, and how --mount's key=value form says the same thing. Evidence: --mount is consumed correctly but reported as unsupported; The converter preserves -v short syntax and warns that --mount must be translated by hand. Stop at the volume persistence exception instead of guessing. Any addition near service volumes and named declarations needs a deployment-specific reason tied to source classification and paths.

Another volumes exception constraint is that for this volumes section keep the original for this volumes section command and warnings for this volumes section beside this candidate file. Evidence: the repository gives no broader runtime or historical proof. Keep the original volume persistence command beside warnings. The comparison shows what service volumes and named declarations contains and which source classification and paths decision remains manual.

Worked example: -v pgdata:/var/lib/postgresql/data and -v /srv/pg/init:/docker-entrypoint-initdb.d:ro — both mounts as Compose YAML

Worked example: -v pgdata:/var/lib/postgresql/data and -v /srv/pg/init:/docker-entrypoint-initdb.d:ro — both mounts as Compose YAML. Build the volume persistence example from synthetic names. Make every service volumes and named declarations item traceable without exposing production source classification and paths details.

The same volumes example sample demonstrates that A separate volumes example boundary is that the volumes list makes persistence assumptions reviewable. Evidence: the volumes list makes persistence assumptions reviewable. The paired volume persistence fact should be visible in service volumes and named declarations. Record that line and avoid assumptions about source classification and paths.

Relative path meaning depends on the eventual Compose file location; the converter does not resolve it

Relative paths — allowed in Compose relative to the file, not in docker run, which is why ./ appears only after conversion. Evidence: relative strings are preserved without resolving a future Compose directory; Relative path meaning depends on the eventual Compose file location; the converter does not resolve it. Translate the volume persistence consequence into one observable service volumes and named declarations difference. Docker owns the later source classification and paths verdict.

The volumes consequence implementation also shows for this volumes section keep the original for this volumes section command and warnings beside for this volumes section this candidate file that volumes consequence fact defines what for this volumes section the browser contributed for this volumes section docker still owns the volumes consequence runtime verdict the for this volumes section operator still owns the volumes consequence security policy the for this volumes section repository still needs the volumes consequence secret removed keep for this volumes section those responsibilities separate when for this volumes section describing the generated service. Split volume persistence responsibilities: conversion writes service volumes and named declarations, the repository removes secrets, and operators validate source classification and paths.

What this does not cover — volume drivers, NFS-backed volumes and tmpfs mounts, which have their own keys

What this does not cover — volume drivers, NFS-backed volumes and tmpfs mounts, which have their own keys. Evidence: --tmpfs maps separately while volume-driver needs manual configuration. Limit volume persistence scope to service volumes and named declarations branches shown here. Neighboring forms and defaults cannot answer source classification and paths questions.

One more volumes scope limit follows from A separate volumes limit boundary is that simple names, host paths, relative paths, variables and Windows drives are classified differently. Treat this volume persistence boundary as an exclusion. Prefer accurate service volumes and named declarations over guesses about source classification and paths.

Takeaway: know which of the three you have — and the converter lays out the volumes list so you can check each one

Takeaway: know which of the three you have — and the converter lays out the volumes list so you can check each one. Audit volume persistence as source option, model field, service volumes and named declarations line and warning. Remove secrets before checking source classification and paths.

Finally, the volumes takeaway source confirms A separate volumes decision boundary is that named sources gain null declarations in top-level volumes. Close volume persistence narrowly: service volumes and named declarations is a candidate; source classification and paths and shell equivalence are not guarantees.