Docker -v to --mount Converter

Convert -v to --mount. They do the same job with one behavioural difference, and that difference is why scripted deployments should use the longer form.

Paste below, or drop a file anywhere on this panel

Or drop a file anywhere on this panel. Nothing is uploaded: the analysis runs in this tab.

The answer appears here

Paste on the left and press Convert. Nothing leaves this tab.

Examples

Real input you can load into the tool above. Each one shows a different thing going wrong, because that is what the tool is for.

A bind mount

The one difference between the syntaxes, and the reason to prefer --mount

/srv/data:/var/lib/data

A path with no source

An anonymous volume with a random name that nothing will ever refer to

/var/lib/data

A relative path

Means three different things across run, --mount and Compose

./data:/var/lib/data

Common mistakes

These are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.

  1. Using -v for a bind mount in a script

    A typo in the host path creates an empty root-owned directory rather than failing, so the container starts against no data and looks healthy.

    Instead:Use --mount type=bind. It errors on a missing source, which is what you want from automation.

  2. Writing -v /var/lib/data with no source

    That is an anonymous volume with a random name. It survives the container, nothing references it, and it is invisible until docker system df shows the size.

    Instead:Name it: -v myapp-data:/var/lib/data.

  3. Assuming a relative path means the same thing everywhere

    docker run resolves it against your shell's directory, --mount rejects it, and Compose resolves it against the compose file's directory.

    Instead:Use absolute paths in anything scripted.

-v creates a missing host path, --mount errors

A typo in a bind mount path gives you a new empty directory owned by root, not an error. The container starts, finds nothing, and initialises itself from scratch.

The failure mode this prevents

A database container with a mistyped data path mounts a fresh empty directory, sees no data, and initialises a new empty database. Everything comes up healthy. The old data is still on disk at the path you meant, and nothing has said a word. --mount fails to start the container instead, which is the outcome you want.

Three things -v can mean, told apart by the source

A path starting with / or . is a bind mount of that host directory. A plain name is a named volume, created if it does not exist. A single path with no colon is an ANONYMOUS volume with a random 64-character name.

Anonymous volumes accumulate invisibly

They survive the container, nothing refers to them, and they only show up in docker volume ls as a wall of hex. This is where the reclaimable gigabytes in docker system df usually come from. Naming the volume costs nothing and makes it backupable.

Relative paths behave differently in the three places you write them

docker run -v resolves against your current directory. --mount refuses a relative path outright. Compose resolves against the compose file's directory, not against where you ran the command. So the same string means three things.

--mount is the only form for some options

tmpfs sizing, some volume driver options, and the clearer readonly spelling. It is also self-documenting, since every part is a key=value rather than a position in a colon-separated string.

What this cannot see

Whether the host path exists, or what is in it. It converts the syntax, in your browser, and touches nothing.

More docker tools

Docker Container Image Reference Parser Is that a registry or a Docker Hub user? Dockerfile Linter What this image will do to you later docker run to Kubernetes YAML And the flags that have no equivalent Docker Compose to Kubernetes And why depends_on has no equivalent Docker Logging Driver Generator json-file never rotates Dockerfile Non-Root USER Generator Numeric, or Kubernetes rejects it Docker OCI Image Labels Generator One of them actually does something Docker Hub Pull Rate Limit Calculator Counted per IP, not per person Docker Registry Storage Calculator Deleting a tag frees nothing Docker Build Context Analyzer All of it uploads before anything runs Docker Compose to docker run Converter Names stop resolving Docker Compose Version Migrator version: is obsolete now Docker Compose Network and Port Viewer Everything reaches everything Docker Command Explainer Which flags hand over the host Docker BuildKit Cache Mount Generator apt deletes the cache you just mounted Docker BuildKit Secret Mount Generator ARG is in docker history forever Docker .dockerignore Pattern Tester *.log does not match logs/app.log Docker Image Manifest Viewer unknown/unknown is not broken Docker Image Config Viewer Anyone who can pull can read your Env Docker Registry Token Decoder Check the scope before the credentials Docker HEALTHCHECK Generator Docker does nothing when it fails Docker Network Subnet Calculator 31 networks, then it stops Docker History Analyzer The rm did not save anything Docker Run to Compose Converter Some flags have no equivalent Docker CMD and ENTRYPOINT Tester Why docker stop takes ten seconds Docker Port Mapping Tester -p reaches past your firewall Docker Restart Policy Simulator The backoff resets after ten seconds Docker Exit Code Explainer 137 is two different problems Docker CPU Limit Converter --cpu-shares limits nothing Docker Memory Limit Calculator -m 512m allows a gigabyte Docker Compose Interpolation Tester An unset variable is an empty string Docker Environment Variable Precedence Tester Your shell does not reach the container Docker Compose Override Merge Previewer An override can add a port, never remove one Dockerfile Multi-Stage Build Analyzer Which stages reach the image Dockerignore Validator It is not .gitignore

Elsewhere on the site