deftools.io Developer Tools

🐳 Docker Run to Compose

Convert a docker run command to a docker-compose.yml file. Paste any docker run flags and get the equivalent compose service.

0 chars

About this tool

Paste any docker run ... command and get its equivalent docker-compose.yml service definition. The tool parses common flags — ports, volumes, environment variables, restart policy, networks, healthchecks, resource limits, and more — and generates a Compose service block that behaves the same way.

Example: docker run -d --name web -p 8080:80 -e DB_URL=postgres://db:5432/app nginx:alpine becomes a Compose service named web with image nginx:alpine, port mapping 8080:80, and environment variable DB_URL.

A docker run command with --restart unless-stopped becomes restart: unless-stopped. Volume mounts are extracted into the volumes: section and bind mounts are generated as type: bind entries.

FAQ

Does this convert every docker run flag?

It handles the most common flags: -d, --name, -p/--publish, -e/--env, --env-file, -v/--volume, --mount, --network, --restart, --label, --hostname, -u/--user, -w/--workdir, --entrypoint, --dns, --init, --privileged, --cap-add/--cap-drop, --tmpfs, --read-only, --shm-size, --expose, --link, --stop-signal, --stop-grace-period, --sysctl, --health-cmd/--health-interval/--health-retries, -m/--memory, --memory-reservation, --cpus, --log-driver/--log-opt, --pid, --ipc, --device, -i/--interactive, -t/--tty, --pull, --platform, --security-opt, --gpus. Less common flags may not be recognised and will appear as comments in the output.

How are named volumes handled?

Named volume arguments (e.g. -v mydata:/var/lib/data) are registered in the top-level volumes: section of the compose file, and referenced by name in the service. Bind mounts (paths starting with /, ./ or ~) are generated as volume entries with explicit bind configuration.

What if my docker run uses --mount instead of -v?

Both syntaxes are supported. --mount type=bind,source=/host,target=/container and --mount type=volume,source=volname,target=/container are parsed and converted to the equivalent compose volume syntax.

Does this cover docker compose top-level keys like networks?

Yes. If the command references a user-defined network (--net somenet), the tool generates both the service-level networks entry and a top-level networks: section. External networks are marked with external: true.

More developer tools

Copied!