DEVELOPER TOOL

Docker Run to Docker Compose Converter

Paste a docker run command and get a docker-compose.yml. Flags that Compose cannot express are listed instead of dropped.

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 runCompose key
--namecontainer_name (and the service name)
-p, --exposeports, expose
-v, --mount, --tmpfsvolumes, tmpfs (named volumes also get a top-level volumes: entry)
-e, --env-fileenvironment, env_file
--restartrestart
--networknetwork_mode for host, none and container:, otherwise networks marked external
-w, -u, -h, --entrypointworking_dir, user, hostname, entrypoint
--cap-add, --privileged, --devicecap_add, privileged, devices
-m, --cpus, --ulimitmem_limit, cpus, ulimits
--health-*, --log-driverhealthcheck, logging
-t, -itty, 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

Frequently asked questions

How do I convert a docker run command to docker-compose?

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.

Which docker run flags does the converter support?

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.

What happens to flags that have no Compose equivalent?

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.

Why is there no version line in the output?

Docker Compose v2 ignores the top-level version key and warns that it is obsolete, so the file starts directly with services.

Does the tool run my command or send it anywhere?

No. It only reads the text in your browser and builds YAML from it. Nothing is executed, uploaded or stored.

Can I convert several containers at once?

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.