# docker run to docker-compose.yml Converter - Both Directions

> Convert docker run to docker-compose.yml and back: ports, volumes, env, networks, healthchecks, limits, logging and GPUs, plus warnings for unsupported flags.

- URL: https://qilingtools.com/en/docker-convert
- Category: Developer Tools (https://qilingtools.com/en/dev)
- Tags: [Converters](https://qilingtools.com/en/tags/convert), [Developer](https://qilingtools.com/en/tags/dev), [DevOps](https://qilingtools.com/en/tags/devops)
- Last updated: 2026-10-26
- Price: Free, no sign-up
- Privacy: Runs locally in the browser; files are never uploaded

Image READMEs usually show one long docker run command, while real deployments are easier to manage as a docker-compose.yml — and sometimes you need the opposite, running one Compose service with plain docker run. This tool converts both ways. The docker run parser follows shell rules for quotes, backslash continuations and several commands chained with &&, and understands -d, --name, -p, -v, --mount, -e, --env-file, --restart, --network and aliases, -w, -u, --entrypoint, --privileged, --cap-add, --device, -l, the --health-* flags, -m / --cpus and other limits, --log-driver / --log-opt, --ulimit, --gpus, --add-host, --dns and more; the command after the image is kept exactly as an argument list. The Compose output is standard YAML with quoted ports, and named volumes and custom networks are declared at the top level. The reverse direction handles short and long port and volume syntax, environment maps or lists, YAML anchors and merge keys, deploy.resources limits and GPUs, orders services by depends_on, rewrites relative bind mounts to $(pwd) and can emit docker network create and docker volume create commands. Anything that cannot be translated, such as --rm, build, multiple networks or deploy.replicas, is listed as a warning.

## How to use

1. Pick a direction and paste docker run commands or a docker-compose.yml
2. Adjust the options and review the warnings
3. Copy or download the generated docker-compose.yml or shell commands

## Features

- docker run → Compose and Compose → docker run
- Multiple commands, quotes and continuations; several services at once
- Ports, volumes, env, networks, healthchecks, limits, logging, GPUs
- Named volumes and custom networks declared automatically
- depends_on ordering plus network / volume create commands
- Warnings for every unsupported flag or key
- Runs locally; nothing is uploaded

## FAQ

### Which docker run flags have no Compose equivalent?

Runtime-only flags such as -d (Compose already runs detached with up -d), --rm (Compose keeps containers; use docker compose run --rm for one-off jobs) and -P (publish all ports randomly) cannot be expressed and are listed as warnings. Almost all other common flags map one to one, and any flag the tool does not recognise is listed so you can handle it by hand.

### Why does the generated docker run join only one network?

docker run accepts a single --network. If a Compose service joins several networks, the container starts on the first one and the tool tells you to attach the rest with docker network connect. Compose also creates project networks automatically, so run the generated docker network create commands first when using plain docker run.

### How are ${VARIABLES} and relative paths handled?

Values containing ${VAR} are wrapped in double quotes so your shell expands them at run time — export the variables first, e.g. set -a; . ./.env; set +a. Relative bind mounts like ./data must be absolute for docker run, so they are rewritten to "$(pwd)/data"; run the commands from the directory that holds the compose file.

### Do I still need the version field?

No. Compose V2 (the docker compose command) ignores the top-level version field and warns that it is obsolete, so it is omitted by default. Tick the option if you still use the legacy docker-compose 1.x.

## Related tools

- [JSON Formatter](https://qilingtools.com/en/json): Free online JSON formatter: beautify or minify, validate with the exact line and column of any error, browse a collapsible tree, sort keys and escape strings.
- [Base64 Encode/Decode](https://qilingtools.com/en/base64): Free online Base64 encoder and decoder: UTF-8 safe, optional URL-safe variant, convert text to Base64 and back in real time. Processed locally, never uploaded.
- [URL Encode/Decode](https://qilingtools.com/en/url-encode): Free online URL encoder and decoder with encodeURIComponent and encodeURI modes. Escapes Chinese, spaces and special characters. Real-time and local, no upload.
- [JWT Decoder](https://qilingtools.com/en/jwt): Free online JWT decoder: decode the header and payload of a JSON Web Token, show expiry and issued-at times, all locally without uploading the token.
- [Timestamp Converter](https://qilingtools.com/en/timestamp): Free online Unix timestamp converter: convert timestamps and dates, auto-detect seconds or milliseconds, and show local, UTC, ISO 8601 and relative time.
- [Hash / Checksum](https://qilingtools.com/en/hash): Free online hash calculator: SHA-1, SHA-256, SHA-384 and SHA-512 of text or any file through the browser crypto API. Files never leave your device.
- [UUID Generator](https://qilingtools.com/en/uuid): Free online UUID generator: create RFC 4122 UUID v4 in bulk with a cryptographic RNG. Options for uppercase, no hyphens and braces, with one-click copy.
- [Base Converter](https://qilingtools.com/en/base-convert): Free online number base converter: convert between binary, octal, decimal, hexadecimal and any base 2–36. Uses BigInt for huge integers, computed locally.
