docker-compose to docker run
Convert a docker-compose.yml into docker run commands.
Related Tools
Convert docker run commands into a docker-compose.yml file.
Convert a docker-compose.yml into Kubernetes Deployment and Service manifests.
Convert a .env file into a docker-compose environment section.
Convert a .env file into a base64-encoded Kubernetes Secret manifest.
Encode or decode Base64 for text and files, Unicode-safe.
Convert a .env file into gh secret set commands for GitHub Actions.
Documentation
What is docker-compose to docker run?
This tool takes a docker-compose.yml file and converts each service into an equivalent standalone docker run command. It's useful when you need to run a single service without installing Docker Compose, embed the exact startup command in a script, or understand exactly what compose is doing under the hood for a given service.
How it works
Each service in services: is parsed into its image, ports, environment variables, volumes, and command, then mapped one-to-one onto --name, -p, -e, and -v flags. The command is built as a backslash-continued multi-line docker run -d \ block so it stays copy-paste-able into a terminal. Any value that isn't a bare identifier (contains spaces, quotes, or shell metacharacters) is automatically single-quoted.
A subtlety worth knowing: notes about things a single docker run invocation simply cannot express — like deploy.replicas or depends_on — are always emitted as standalone # comment lines placed before the command block, never interleaved between its backslash-continued lines. That's deliberate: bash does not treat # as a comment marker when it's the next token after a line-continuation backslash, so a comment dropped in the middle of a docker run \ block would be parsed as a literal (and almost certainly invalid) shell argument if someone copy-pasted the whole thing. Keeping every note above the command guarantees the generated script is always safe to paste and run as-is.
Features
- Converts ports, environment variables, volumes, and command overrides to their flag equivalents
- Flags
depends_onanddeploy.replicaswith explanatory comments instead of silently dropping them - Skips build-only services (no
image:) with a comment telling you to build and substitute the image name first - Automatically shell-quotes values containing spaces or special characters
- Copy, download as a
.shfile, or load sample data
Example
Input:
services:
web:
image: nginx:latest
ports:
- "8080:80"
environment:
- NODE_ENV=production
volumes:
- ./html:/usr/share/nginx/html
depends_on:
- dbOutput:
# web depends_on: db — start those containers first; # docker run does not sequence startup order the way depends_on does. docker run -d \ --name web \ -p 8080:80 \ -e NODE_ENV=production \ -v ./html:/usr/share/nginx/html \ nginx:latest
If web also had deploy: {replicas: 3}, three comment lines explaining that docker run starts exactly one container would appear directly above that same command block — not inside it.
Common errors
"No services found" means the YAML doesn't have a top-level services: map — check indentation, since YAML is whitespace-sensitive. A service that resolves to no output at all almost always means it only defines build: with no image: — that service gets a comment instead of a command, since docker run can't build images.
Best practices
Read the comment lines above each command before running it — they call out exactly what compose semantics (replica counts, startup ordering) got lost in translation to a single docker run call. For multi-service stacks with real startup dependencies, prefer keeping Compose (or moving to Kubernetes) over stitching together standalone docker run commands by hand.
Frequently Asked Questions
Why does the output use -d (detached mode)?▾
Detached is the closest match to how docker-compose up normally runs services in the background. Drop -d from the command if you want the container attached to your terminal instead.
What happens to a service with no "image", only "build"?▾
docker run can't build an image any more than Kubernetes can — it only starts containers from images that already exist. That service is skipped with a comment telling you to run docker build first and substitute the resulting image name in.
Does depends_on control which command runs first?▾
No — each docker run command is independent, so a comment lists the dependency instead of silently ignoring it. Start the commands in dependency order yourself (or use docker-compose, which does understand depends_on, if you need this automated).
What about deploy.replicas?▾
docker run always starts exactly one container per invocation — there's no concept of replica count. If a service specifies replicas > 1, a comment flags it rather than silently dropping the requirement; running more than one instance means looping the command with distinct --name and -p values yourself.