About this docker run to docker compose converter
This converter reads a docker run command and writes the equivalent docker-compose.yml. Paste the command, including multi-line commands that end each line with a backslash, and the tool maps the flags it understands to Compose keys. It runs in your browser, so the command, which may contain passwords in -e flags, is not uploaded.
How flags are mapped
| docker run | Compose key |
|---|---|
--name | container_name (and the service name) |
-p, --expose | ports, expose |
-v, --mount, --tmpfs | volumes, tmpfs (named volumes also get a top-level volumes: entry) |
-e, --env-file | environment, env_file |
--restart | restart |
--network | network_mode for host, none and container:, otherwise networks marked external |
-w, -u, -h, --entrypoint | working_dir, user, hostname, entrypoint |
--cap-add, --privileged, --device | cap_add, privileged, devices |
-m, --cpus, --ulimit | mem_limit, cpus, ulimits |
--health-*, --log-driver | healthcheck, logging |
-t, -i | tty, stdin_open |
Anything after the image name is treated as the container command and written as a command list, so arguments with spaces stay intact.
Flags that cannot be converted
Some flags describe how you start a container, not how it is defined. The tool does not drop them silently. It lists each one in a warning box and adds a comment line inside the YAML. -d becomes docker compose up -d, and --rm has no Compose key (use docker compose run --rm for one-off containers). -P publishes every exposed port to random host ports, which Compose cannot express, so list ports explicitly. Flags the tool does not know are reported too, so check them by hand.
Example
The command docker run -d --name web -p 8080:80 -e TZ=UTC --restart unless-stopped nginx:1.27 becomes a service called web with image: nginx:1.27, ports set to "8080:80", one environment entry and restart: unless-stopped. The -d flag is listed as handled outside the file.
Good to know
- The file starts with
services:and has noversion:line, because current Docker Compose ignores it. - A dollar sign inside single quotes is written as
$$, so Compose does not treat it as a variable.$(pwd)and$PWDbecome., the project folder. - A custom network named in
--networkis markedexternal: true, becausedocker runexpects it to exist already. Remove that line if you want Compose to create it. - Check the result with
docker compose configbefore relying on it.
Frequently asked questions
Paste the command into the box and press Convert. The tool writes a docker-compose.yml with a service for the command. Save it as docker-compose.yml or compose.yaml and start it with docker compose up -d.
It maps ports, volumes and mounts, environment variables and env files, restart policy, container name, networks, user, working directory, entrypoint and command, capabilities, devices, resource limits, health checks, logging and several other options. Others are listed as not mapped.
They are not dropped silently. Each one appears in a warning list and as a comment in the YAML, with a note on what to do instead, for example docker compose run --rm for --rm.
Docker Compose v2 ignores the top-level version key and warns that it is obsolete, so the file starts directly with services.
No. It only reads the text in your browser and builds YAML from it. Nothing is executed, uploaded or stored.
Yes. Put one docker run command per line (a backslash at the end of a line continues the same command) and each becomes its own service in one file.