docker run to Docker Compose converter

Paste a docker run command and get the same container as a Compose service, checked by the Compose Analyzer. Nothing is run, and nothing leaves this page.

Stays in your browser. What you paste or choose is read on this page only. It is not sent to a server, not saved in the link or in browser storage, and never part of analytics.

Paste the text, or choose a file from your computer. Up to 64 KiB.

0 of 64 KiB

The other way: Compose to docker run

What it does

It reads one docker run command the way the Docker CLI reads it (short and long options, = values, quotes, backslash line breaks) and writes a docker-compose.yml with one service that starts the same container: ports, volumes and mounts, environment, networks, restart policy, user, capabilities, resource limits, logging and health check.

How it works

  1. The command is split into words like a POSIX shell would, without running or expanding anything. Anything that would run a second command (;, &&, |, redirections, $( ) or backticks) stops the conversion with its position.
  2. Each option maps to the Compose attribute with the same effect. Options Compose cannot express, and CLI-only options such as --rm and -d, are listed as notes instead of being dropped silently.
  3. A value whose name or shape looks like a secret (PASSWORD, TOKEN, *_KEY, a URL with a password) is replaced by a reference to .env, and .env.example lists the variable empty. Named volumes keep their name, and networks the command joined are declared external.
  4. The file is then checked by the Compose Analyzer, the same rules as /tools/compose-analyzer.

Example

The PostgreSQL command from the official image documentation, converted:

Input
docker run
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
Output
docker-compose.yml
# Converted from a docker run command by ANAROQ (https://anaroq.com/tools/docker-run-to-compose), converter 1.0.0.
# Review it before use. Nothing was run.

services:
  some-postgres:
    image: "postgres"
    container_name: "some-postgres"
    environment:
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}"
Output
.env.example
# Variables of the docker-compose.yml converted by ANAROQ (https://anaroq.com/tools/docker-run-to-compose).
# Copy this file to .env and fill in every value. Never commit .env.
# The docker run command had these values inline; ANAROQ does not copy them here.

# Secret, required.
POSTGRES_PASSWORD=

Limits

  • One command at a time, and docker run (or docker container run) only: not docker create, Podman, docker-compose v1 or Swarm.
  • Shell variables such as $PWD stay variables: Compose reads them from the environment or .env when it starts.
  • Without --network, docker run uses the default bridge network; Compose puts the service on the project's own network, so containers started separately do not see it by name.
  • Static conversion and static checks: nothing is started, so the image, ports and paths are not verified.

Sources

  1. Docker Docs: docker container run
  2. Docker Docs: Compose file reference
  3. Compose Specification

Updated

Next step

Docker Compose Analyzer

A free public tool by ANAROQ, a company building compute infrastructure. What ANAROQ is building