FROM A COMMAND TO A CONFIGURATION

Docker Run to Compose.

Turn a long docker run command into a readable Compose file. Convert ports, environment variables, volumes and more — then copy your YAML.

docker runcompose.yaml
Browser-only conversion
01

Paste one command. Quoted arguments and backslash line continuations are supported. Updates as you type.

02

compose.yaml

services:
  web:
    image: "nginx:alpine"
    container_name: "web"
    ports:
      - "8080:80"
    volumes:
      - "./html:/usr/share/nginx/html:ro"
    restart: "unless-stopped"
    network_mode: "bridge"

5 options parsed · 1 serviceYAML

Before you run it

  • Detached mode is a launch option. Use docker compose up -d to run the service in the background.
  • Relative bind paths are resolved beside compose.yaml. Keep the file in the intended working directory or use absolute paths.
  • network_mode: bridge preserves Docker run’s default network. Remove it if you want Compose to create its own project network instead.
Check the file locallydocker compose config

No account. No command execution. Your input stays in this browser.

Why convert docker run to Docker Compose?

A docker run command is convenient for starting a container, but a long command can be difficult to review or reproduce. A Compose file puts the same settings into named fields: the image, exposed ports, environment, mounts and restart policy can be read and edited together.

This Docker Run to Compose converter prepares a single-service compose.yaml file from your command. Use it as a starting point for documenting a container setup, moving a service to another server, or bringing a hand-written command into version control. It works locally in the browser and never connects to your Docker daemon.

How to convert a Docker command to Compose YAML

  1. Paste one docker run or docker container run command. Commands split over lines should use backslash continuations.
  2. Optionally enter a service name. Otherwise, the container name or image name is used.
  3. Read the conversion notes, particularly for external volumes, networks and launch-only options.
  4. Copy the output or download compose.yaml. Place referenced files and bind-mounted directories in their intended locations.
  5. Run docker compose config locally to check the Compose configuration before starting it.

For a long-running service, docker compose up -d starts it in the background. The converter does not run either command for you.

Docker run flags and their Compose equivalents

Short and long options are accepted, including forms such as -p8080:80, --name=web and -dit. Options must appear before the image; everything after the image is the container command.

Docker runCompose fieldConversion
IMAGEimageThe image reference and tag are retained.
--namecontainer_nameAlso supplies the default service name.
-p, --publishportsHost-to-container mappings stay quoted strings.
-e, --envenvironmentSupports NAME=value and host-provided NAME entries.
--env-fileenv_fileUses raw format; requires Compose 2.30.0 or newer.
-v, --volumevolumesSupports bind mounts, named volumes and anonymous volumes.
--mountvolumesSupports bind and volume mounts with selected options.
--networknetworks / network_modeExisting named networks are declared external.
--restartrestartIncludes always, unless-stopped and on-failure.
-u / -wuser / working_dirKeeps the container user and working directory.
--entrypointentrypointPreserves a single executable, without splitting spaces.
Arguments after IMAGEcommandAn argument list preserves quoting and empty arguments.
-i / -tstdin_open / ttyInteractive settings are included when requested.
--memory / --cpusmem_limit / cpusMaps the container resource limits.
--health-*healthcheckMaps the command, interval, timeout, start period and retries.
--log-driver / --log-optloggingRetains the logging driver and options.

Other supported settings include DNS, extra hosts, capabilities, devices, security options, labels, temporary filesystems, shared memory, process limits, read-only filesystems and privileged mode. An unsupported option stops conversion so it cannot disappear from the generated configuration unnoticed.

Example: a Docker run command becomes compose.yaml

This command starts an Nginx container named web, publishes host port 8080 and uses an automatic restart policy:

docker run -d --name web -p 8080:80 \
  --restart unless-stopped nginx:alpine

The equivalent service configuration is:

services:
  web:
    image: "nginx:alpine"
    container_name: "web"
    ports:
      - "8080:80"
    restart: "unless-stopped"
    network_mode: "bridge"

Detached mode is a choice made when starting Compose, so -d becomes a launch instruction rather than a YAML field. The explicit bridge network preserves the default networking used by Docker run.

Keep the right data volumes and networks

A named Docker volume and a host directory are different kinds of mount. For -v data:/data, the converter declares data as an external volume with its exact name. This helps reuse an existing volume instead of accidentally starting with a new Compose project-prefixed volume. If this is a fresh setup, create the volume first or remove external: true.

For a bind mount such as -v ./html:/usr/share/nginx/html:ro, the relative path is interpreted beside the Compose file. Move the YAML file without its directory and the mount may point somewhere else. Absolute paths make the intended source explicit. A bind mount written with --mount keeps its stricter missing-source behavior through create_host_path: false.

Existing custom networks are also declared external. If your command does not specify a network, the output uses network_mode: bridge. Remove that field if you deliberately want Compose to create a project network and provide service-name discovery. Host networking cannot be combined with published ports in the generated configuration.

Supported input and conversion limits

The input is one POSIX-style shell command, optionally prefixed with sudo. Single and double quotes, escaped characters and backslash-newline continuations are supported. Windows PowerShell, CMD syntax, shell pipelines, redirections, multiple commands and Docker CLI global options are outside this converter’s scope.

The browser cannot read your shell environment or evaluate $(pwd). Replace shell variables and substitutions with resolved values before converting. Literal dollar signs inside single-quoted or escaped arguments are preserved with Compose’s $$ escaping. An environment entry without a value, such as -e API_TOKEN, is left for Compose to resolve on the deployment machine.

The converter preserves env-file contents using format: raw, which needs Docker Compose 2.30.0 or later. It does not open the referenced file, inspect an image, validate application credentials, check port availability or prove that a container will start. Use the generated file together with the conversion notes and a local configuration check.

Docker Run to Compose FAQ

Is this a free online converter?

Yes. You can paste a command, inspect the YAML, and copy or download it without creating an account. Conversion happens in your browser; the tool does not upload commands or execute them.

Why is there no version field?

The output uses the current Compose Specification with a top-level services mapping. It does not add the legacy version header. Use the modern docker compose command to validate and run the file.

What happens to --rm?

Automatic removal is a runtime choice, not a service field. For a one-off task, use docker compose run --rm --service-ports SERVICE, replacing SERVICE with your service name. The --service-ports option applies port mappings that Compose run otherwise does not publish by default.

Can I paste several docker run commands?

Convert one command at a time. To build a multi-service project, merge the generated service entries and reconcile shared volumes and networks manually. This tool does not infer dependencies between containers.

Why do I see an unsupported-option message?

Some Docker features need more context than a run command supplies. Flags such as --gpus, --link, extended network options and advanced mount settings currently require manual configuration. The tool withholds output instead of dropping those arguments.

Will the service name change my container name?

The optional service name changes the key under services. An explicit --name remains in container_name. If that name is already used by a running container, resolve the name conflict before starting Compose.

For details, consult the official Docker run reference, Compose service reference and Compose interpolation guide.