Developer tools · Docker run to Docker compose converter
Quotes, line breaks and $VARS: parsing a docker run command correctly
· How it works
docker command-line quoting
A docker run command is shell input before Docker ever sees it. This post explains how quoting and line continuations change what the tokens are, and why no converter can expand your shell variables.
The converter received a literal $HOME — the command works in your terminal because the shell expands it before docker runs
The converter received a literal $HOME — the command works in your terminal because the shell expands it before docker runs. Evidence: $HOME remains text because the tokeniser performs no expansion. Reproduce shell tokenization with disposable literals. Pair each source occurrence with quoted tokens and continuations; reserve expansion and Windows parsing for destination review.
The quoting incident also reveals that A separate quoting incident boundary is that single quotes are literal and double quotes process documented escapes. Evidence: single quotes are literal and double quotes process documented escapes. This shell tokenization constraint is a stopping point. Inspect quoted tokens and continuations without manufacturing behavior, then document a host check for expansion and Windows parsing.
This tokeniser resembles selected POSIX shell word rules but performs no variable or command expansion
Shell first, Docker second — the tokens Docker receives are the result of the shell's quoting, splitting and expansion. Evidence: selected POSIX-like word rules are implemented without becoming a shell; This tokeniser resembles selected POSIX shell word rules but performs no variable or command expansion. Trace shell tokenization tokens into quoted tokens and continuations. Separate ordered values from last-value fields; expansion and Windows parsing is outside collection.
A related quoting mechanism boundary is that for this quoting section keep the original for this quoting section command and warnings for this quoting section beside this candidate file. Evidence: the repository gives no broader runtime or historical proof. Use this shell tokenization fact to predict one member or scalar in quoted tokens and continuations. Check warnings before deciding anything about expansion and Windows parsing.
Backslash-newline continuations — why the trailing backslash is a shell feature and a stray space after it breaks the command
Backslash-newline continuations — why the trailing backslash is a shell feature and a stray space after it breaks the command. Evidence: backslash-newline disappears while a terminal lone backslash fails. Judge shell tokenization serialization from its model. Quoting in quoted tokens and continuations protects types but gives no operational proof for expansion and Windows parsing.
The second quoting serialization observation is A separate quoting output boundary is that a wiki sample can be normalized and its literal tokens inspected. Evidence: a wiki sample can be normalized and its literal tokens inspected. This shell tokenization output separates settings from unavailable context. Keep quoted tokens and continuations reviewable and check expansion and Windows parsing independently.
Single quotes, double quotes and spaces in values — -e MSG='hello world' versus -e MSG=hello world
Single quotes, double quotes and spaces in values — -e MSG='hello world' versus -e MSG=hello world. Stop at the shell tokenization exception instead of guessing. Any addition near quoted tokens and continuations needs a deployment-specific reason tied to expansion and Windows parsing.
Another quoting exception constraint is that A separate quoting exception boundary is that Docker option arity follows tokenisation and Windows rules are absent. Evidence: Docker option arity follows tokenisation and Windows rules are absent. Keep the original shell tokenization command beside warnings. The comparison shows what quoted tokens and continuations contains and which expansion and Windows parsing decision remains manual.
Dollar expressions, subshell syntax and tildes remain literal because the converter is not a shell
Variables and subshells — $PWD, $(id -u) and ~ are expanded by your shell, so a converter sees them literally. Evidence: subshell notation backticks dollar variables and tilde are never evaluated; Dollar expressions, subshell syntax and tildes remain literal because the converter is not a shell. Build the shell tokenization example from synthetic names. Make every quoted tokens and continuations item traceable without exposing production expansion and Windows parsing details.
The same quoting example sample demonstrates that for this quoting section keep the original for this quoting section command and warnings for this quoting section beside this candidate file. The paired shell tokenization fact should be visible in quoted tokens and continuations. Record that line and avoid assumptions about expansion and Windows parsing.
Worked example: cleaning up a wiki-pasted command — normalising continuations and quoting before conversion, then checking the YAML
Worked example: cleaning up a wiki-pasted command — normalising continuations and quoting before conversion, then checking the YAML. Translate the shell tokenization consequence into one observable quoted tokens and continuations difference. Docker owns the later expansion and Windows parsing verdict.
The quoting consequence implementation also shows A separate quoting effect boundary is that $HOME remains text because the tokeniser performs no expansion. Split shell tokenization responsibilities: conversion writes quoted tokens and continuations, the repository removes secrets, and operators validate expansion and Windows parsing.
Windows shell quoting and complete POSIX expansion are both outside this parser
What this does not cover — docker run's own option parsing quirks, such as = versus space, and Windows shell quoting differences. Evidence: Docker option arity follows tokenisation and Windows rules are absent; Windows shell quoting and complete POSIX expansion are both outside this parser. Limit shell tokenization scope to quoted tokens and continuations branches shown here. Neighboring forms and defaults cannot answer expansion and Windows parsing questions.
One more quoting scope limit follows from keep the original command for this quoting section and warnings beside this candidate file. Treat this shell tokenization boundary as an exclusion. Prefer accurate quoted tokens and continuations over guesses about expansion and Windows parsing.
Takeaway: give the converter what Docker would see — and replace shell variables with literal values or Compose ${VAR} interpolation
Takeaway: give the converter what Docker would see — and replace shell variables with literal values or Compose ${VAR} interpolation. Evidence: reliable input means supplying literal words intended for parsing. Audit shell tokenization as source option, model field, quoted tokens and continuations line and warning. Remove secrets before checking expansion and Windows parsing.
Finally, the quoting takeaway source confirms A separate quoting decision boundary is that backslash-newline disappears while a terminal lone backslash fails. Close shell tokenization narrowly: quoted tokens and continuations is a candidate; expansion and Windows parsing and shell equivalence are not guarantees.