Home › Developer Tools › Docker Run to Compose Converter

Docker Run to Compose Converter

Paste one or more docker run commands and get a clean docker-compose.yml with ports, volumes, environment variables, restart policies, networks, health checks and resource limits. Switch direction to turn a compose file back into docker run commands.

Last updated:

    Advertisement
    Advertisement

    How to use the Docker Run to Compose Converter

    1. Paste your docker run commands in the left box, one or several. Multi-line commands with backslashes are fine.
    2. Read the compose file on the right. It updates as you type, with each container as a service.
    3. Check the notes under the output for flags that were ignored or need attention.
    4. Copy or download docker-compose.yml and start everything with docker compose up -d.
    5. Going the other way? Switch to Compose → docker run, paste a compose file and get the equivalent shell commands.

    docker run flags and their compose keys

    docker rundocker-compose.ymlExample
    --name webcontainer_name (and the service name)container_name: web
    -p 8080:80ports- "8080:80"
    -v data:/var/lib/xvolumes + top-level volumes- data:/var/lib/x
    -v ./src:/app:rovolumes (bind mount)- ./src:/app:ro
    --mount type=bind,…volumes long syntaxtype: bind, source, target
    -e KEY=valueenvironmentKEY: value
    --env-file .envenv_file- .env
    --restart unless-stoppedrestartrestart: unless-stopped
    --network mynetnetworks + top-level networks- mynet
    --network hostnetwork_modenetwork_mode: host
    -w /app, -u 1000working_dir, useruser: "1000"
    --memory 512m --cpus 1.5mem_limit, cpusmem_limit: 512m
    --health-cmd "…"healthcheck.test["CMD-SHELL", "…"]
    --gpus alldeploy.resources.reservations.devicescapabilities: ["gpu"]
    -itstdin_open + ttytty: true
    image and trailing argumentsimage, commandcommand: ["npm", "start"]

    Everyday docker compose commands

    CommandWhat it does
    docker compose up -dCreate and start all services in the background
    docker compose psList the project's containers and their health
    docker compose logs -f apiFollow the logs of one service
    docker compose pull && docker compose up -dUpdate images and recreate changed containers
    docker compose exec db psql -U appRun a command inside a running service
    docker compose configValidate the file and print it with variables resolved
    docker compose downStop and remove containers and networks (add -v to delete named volumes too)

    Things that do not translate one to one

    • Names get a project prefix. Compose names networks and volumes <project>_<name>. To attach to data or networks you created with docker run, declare them with external: true.
    • Relative paths. In compose, ./data is relative to the compose file. With docker run, use an absolute path or $(pwd)/data.
    • Service discovery. Compose services resolve each other by service name automatically. With docker run you need a user-defined network (the default bridge has no DNS).
    • Start order. depends_on (optionally with condition: service_healthy) only exists in compose. When running by hand, start databases first.
    • Variables. Compose substitutes ${VAR} and ${VAR:-default} from the shell and the .env file next to the compose file. A literal $ must be written as $$.

    Frequently asked questions

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

    Each docker run becomes one service. The image goes to image, --name to container_name, -p to ports, -v to volumes, -e to environment, --restart to restart and --network to networks. Paste the command into this tool to get the YAML automatically, then run docker compose up -d in the folder with the file.

    Is the version line still needed in docker-compose.yml?

    No. The Compose Specification used by Docker Compose v2 ignores the top-level version key and newer versions warn that it is obsolete, so this tool leaves it out. The file name can be compose.yaml or docker-compose.yml.

    What happens to --rm and -d?

    Compose has no equivalent of --rm for long-running services, so it is dropped with a note; use docker compose down to remove containers. -d is not part of the file either: you pass it when starting, as in docker compose up -d.

    Why are named volumes listed at the bottom of the file?

    Compose requires every named volume used by a service to be declared under the top-level volumes key. Bind mounts that start with /, ./ or ~ are host paths and do not need a declaration.

    Will my containers keep the same network and volume names?

    Compose prefixes the networks and volumes it creates with the project name (usually the folder name), for example myapp_data. To reuse existing ones created with docker run, mark them external: true, or set an explicit name.

    Can services reach each other by name?

    Yes. Compose puts all services on a default network where each service name is a DNS hostname, so the app can connect to db:5432. With plain docker run you need a user-defined network for that, which is why the reverse conversion creates one.

    Is my command sent anywhere?

    No. Parsing and conversion run entirely in your browser. Environment variables and secrets in your commands never leave your computer.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    Dockerfile GeneratorGenerate a production Dockerfile and .dockerignore for Node, Python, Go or a static nginx site.Nginx Config GeneratorBuild an nginx server block: static site, SPA, reverse proxy or PHP, with SSL, gzip and redirects.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.Random String GeneratorGenerate secure random strings and tokens in bulk with any length and character set.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.Gitignore GeneratorBuild a .gitignore from 50+ templates for languages, frameworks, IDEs and OS, merged and deduped.License GeneratorCreate a LICENSE file for MIT, Apache, GPL, BSD, ISC, MPL or Unlicense with your name and year.ULID GeneratorGenerate sortable ULIDs and UUID v7 in bulk, monotonic option, and decode their timestamps.Htpasswd GeneratorCreate .htpasswd entries with bcrypt, APR1-MD5 or SHA-1 for Apache and Nginx basic auth.Placeholder Image GeneratorCreate placeholder images in any size, color and text as PNG, JPG, WebP, SVG or data URI.Ads.txt GeneratorCreate or validate ads.txt and app-ads.txt files: seller lines, cert IDs and variables.HTML Boilerplate GeneratorTick the options you need and get a clean HTML5 starter template with meta, OG tags and CSS reset.JSON to Zod SchemaInfer a Zod (or Yup) schema from sample JSON with optional, nullable and z.infer types.Linux Commands Cheat SheetSearchable Linux and bash command reference with flags explained, examples and copy buttons.LLMs.txt GeneratorBuild an llms.txt file for AI crawlers: summary and link sections, import from your sitemap.Nano ID GeneratorGenerate secure Nano IDs with custom alphabet, length and count, plus a collision calculator.OpenAPI / Swagger ViewerView OpenAPI 2/3 JSON or YAML as interactive API docs with validation and an endpoint list.package.json GeneratorFill a form and get a valid, npm-ready package.json with scripts, dependencies and checks.PKCE Code Challenge GeneratorGenerate an OAuth 2.0 PKCE code_verifier and S256 code_challenge, build auth URLs, verify pairs.README GeneratorFill in a form and get a polished README.md with badges, install, usage and license, live preview.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Commit Message GeneratorBuild Conventional Commit messages with type, scope, body, breaking change and issue refs.Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.Docker Compose GeneratorBuild a docker-compose.yml with a form: services, ports, volumes, env, healthchecks and presets.Dummy File GeneratorCreate test files of an exact size in KB, MB or GB with zeros, random bytes or text.FFmpeg Command GeneratorPick a task and options, get the exact ffmpeg command with every flag explained.Folder Tree GeneratorTurn a local folder or an indented list into an ASCII directory tree for your README.Pivot Table MakerBuild pivot tables from CSV or Excel by drag and drop: sum, count, average, charts, export.SQL Query BuilderBuild SELECT queries visually: joins, filters, GROUP BY, ORDER BY and LIMIT, as clean SQL.Truth Table GeneratorType a logic expression and get its full truth table, minterms and canonical DNF/CNF.TypeScript PlaygroundWrite TypeScript with live type checking, see the compiled JavaScript and run it in your browser.Article Schema GeneratorCreate Article, BlogPosting or NewsArticle JSON-LD with headline, authors, dates and images.Event Schema GeneratorCreate Event JSON-LD with dates, venue or online location, tickets, organizer and performers.Google Search Query BuilderBuild advanced Google searches with site:, filetype:, intitle:, exact phrases and date operators.HowTo Schema GeneratorCreate HowTo JSON-LD with steps, tools, supplies, total time and cost, then copy it.Htaccess GeneratorBuild an Apache .htaccess file: HTTPS, www, gzip, caching, error pages, IP blocks, hotlinks.HTML Email Template BuilderDrag and drop blocks to build a responsive, table-based HTML email with inline styles.Organization Schema GeneratorCreate Organization JSON-LD with logo, URL, contact points, address and social profiles.PIN GeneratorGenerate random 4, 6 or 8-digit PINs that avoid sequences, repeats, dates and common PINs.Product Schema GeneratorBuild Product JSON-LD with price, availability, brand, GTIN, ratings and reviews.Question Keyword GeneratorFind the questions people ask about a topic, grouped by who, what, why, how, can and more.Recipe Schema GeneratorCreate Recipe JSON-LD with ingredients, steps, prep and cook times, nutrition and ratings.Security Headers GeneratorPick HSTS, CSP, frame, referrer and permissions options and get Apache, Nginx, Netlify or Cloudflare config.SKU GeneratorBuild consistent SKUs from brand, category, size and color, then export every variant as CSV.Typography Scale GeneratorBuild a modular type scale from a base size and ratio, then copy CSS variables or a Tailwind config.WordPress Salt GeneratorGenerate fresh WordPress security keys and salts for wp-config.php, .env or Docker in one click.ANSI Color Code GeneratorStyle terminal text with 16, 256 or RGB colors and get escape codes for bash, Python, JS and C.Apache Virtual Host GeneratorCreate an Apache VirtualHost config with SSL, redirects, reverse proxy or PHP-FPM in seconds.Bash Prompt GeneratorDrag and drop a custom PS1 prompt for bash or zsh with colors, git branch and a live preview.Changelog GeneratorTurn Conventional Commit messages into a grouped Keep a Changelog Markdown file per version.cURL Command BuilderBuild curl commands from a form: method, headers, query, JSON or form body, auth and flags.Docker Compose to KubernetesConvert docker-compose.yml into Kubernetes Deployment, Service, ConfigMap and PVC manifests.Docker Compose ValidatorCheck a docker-compose.yml for YAML errors, schema mistakes, broken references and deprecated keys.Dockerfile LinterLint a Dockerfile for best practices: pinned tags, apt cleanup, non-root USER and layer count.Dockerignore GeneratorBuild a .dockerignore from Node, Python, Go and Java templates, plus your own entries.ESLint Config GeneratorGenerate a flat eslint.config.js for JavaScript, TypeScript, React or Node with rule presets.Git Branch Name GeneratorTurn a ticket ID and title into a clean, valid git branch name like feature/PROJ-12-add-login.
    See all 85 Code Generators & Builders →