Back to guides

docker run to Compose|Turn a docker run one-liner into Compose without hand-editing YAML

README gave you `docker run -d -p …`. You want a compose file. Here’s how WoDeTool maps ports, volumes, and env flags — and where people usually slip.

By WGinit · July 16, 2026 · 5 min read · 14 views

Why bother converting

docker run is fine for a quick try; Compose is easier to diff in git and hand to the team. Hand-copying flags into YAML is where -e values and quoting disappear.

Docker Run → Compose parses the CLI in the browser and emits a services block—you do not need Docker installed just to preview mapping.

Steps that usually work

Copy the full docker run (backslash continuations are fine) into Docker Run → Compose. Check image, ports, volumes, and environment against the original flags.

Save as docker-compose.yml, then run docker compose config locally once. Rotate passwords or tokens that appeared in the command; do not commit real secrets.

What breaks

PowerShell and bash quote differently—paste bash style when you can. Keep -p, -v, and -e pairs intact; one docker run is one service, then merge YAML for stacks.

JSON↔YAML helps when indentation looks wrong after a second pass.

End-to-end workflow (diagram)

Validate on a short single-port docker run before you paste the fifteen-flag production command.

Privacy, limits, and triage

Paste staging or redacted commands only; real DB passwords and cloud tokens do not belong in browser tools or slack screenshots—rotate anything that leaked during drafting.

Use the diagram for anonymous volumes and --env-file hand fixes; footer links open the compose and YAML tools together.

FAQ

A dozen -e flags on one docker run line: Paste the full line into Docker run to Compose and match every environment and ports entry to the CLI.

$(pwd) in a volume bind: Usually preserved verbatim—re-check paths and permissions on the target host before commit.

Teammates want YAML for review: Round-trip drafts through JSON↔YAML, or convert existing YAML to JSON before editing in the run converter.

Base64-wrapped env blobs: Decode in Base64 to .env text, wire env_file in Compose, keep secrets out of git.

Worked example (step by step)

1. You inherit docker run -d --name redis-cache -p 6379:6379 -e REDIS_PASSWORD=StagingOnly123 redis:7.2-alpine.

2. Paste into Docker run to Compose to get a services.redis-cache block.

3. Confirm ports is "6379:6379" and environment lists REDIS_PASSWORD=StagingOnly123.

4. Drop the block into docker-compose.staging.yml with image: redis:7.2-alpine.

5. When multiple services need tidy YAML, round-trip the draft with JSON↔YAML.

6. Decode any Base64 env placeholder in Base64 before it lands in .env.

7. Run docker compose -f docker-compose.staging.yml config locally; port 6379 should bind cleanly.

8. Pair scheduled jobs with Cron Expression separately—the schedule is not part of the compose conversion.

From one-liner to service blocks

Paste docker run with published ports, env flags, and volume mounts into Docker Run→Compose. The converter expands -e pairs and bind mounts into YAML you can drop into docker-compose.yml for staging parity.

Named volumes and :ro suffixes should survive conversion; double-check ephemeral --rm containers are not silently promoted to restart policies you did not want.

When the run line uses --network host, compose semantics differ on Mac and Windows—annotate the YAML with a comment that teammates on Linux wrote the original.

Published port mappings like -p 127.0.0.1:5432:5432 should stay bind-specific in compose ports arrays—do not widen to 0.0.0.0 accidentally during cleanup.

Privileged --privileged flags convert to privileged: true in compose—grep the output before pushing to shared clusters.

UID/GID mount flags from Linux notebooks may not translate to rootless compose on laptops—annotate ownership assumptions.

Publish 80:8080 pairs where the image EXPOSE does not match runtime—annotate which port the app binds.

Env files and secrets

Inline -e SECRET=foo in a run command becomes literal YAML values. Move secrets to .env before committing; the converter is faithful, not security-aware.

Multi-line env values sometimes break naive parsers; split them in the tool output manually and validate with a local docker compose config.

Base64-wrapped kube-style env vars belong in orchestrator config, not compose—decode with Base64 Decoder only to inspect, not to paste back into git.

Init containers and sidecars never appear in a plain docker run one-liner; add second services manually after conversion.

Device mounts (--device) are easy to miss in review; highlight them in the PR when converting notebook run lines.

Tmpfs mounts from --tmpfs should map to tmpfs size limits in compose for CI memory caps.

GPU flags from docker run rarely convert cleanly—expect manual deploy.resources additions.

YAML polish for ops handoff

Run the generated fragment through JSON↔YAML if your team standardizes on two-space indent and sorted keys—some editors diff cleaner.

Healthchecks and depends_on are not inferred from docker run; add them after conversion when moving from notebook experiments to CI.

Tag the image digest in compose when reproducibility matters; latest in a converted file is just what the run line had.

Validate image tags against your registry mirror; compose files copied from tutorials often reference Docker Hub names your CI mirror rewrites.

Compose version headers matter for deploy keys; add version: or modern compose spec only after your runtime docs say which.

After JSON↔YAML cleanup, run docker compose config before the PR leaves draft.

Keep the original run line in a comment above the service block for audit trail.

Flags compose still cannot express

Host bind mounts with SELinux flags may still need manual :Z edits after docker run to Compose drafts the service block.

Copy-paste reference

Paste the left side into docker run to Compose; adjust volume lines if the converter flags an unsupported flag.

docker run -d --name api -p 8080:8080 \
 -e NODE_ENV=staging \
 -v /data/cache:/cache \
 ghcr.io/acme/api:1.4.2

Related tools

Related guides