# Docker Run to Compose

Turn a docker run command into a Docker Compose service. Ports, volumes and mounts, environment variables, env files, restart policy, networks, resource limits, health checks, logging and most other run options become their compose keys, named volumes and networks are declared at the top level and the command after the image becomes the service command.

## Frequently asked questions

### Which options are converted?

Names, ports, volumes and --mount, environment variables and env files, restart, network or network_mode, working directory, user, entrypoint, hostname, labels, extra hosts, capabilities, privileged and read-only mode, memory and CPU limits, shm size, stop signal and timeout, DNS settings, devices, tmpfs, sysctls, security options, ulimits, logging, health checks, platform, pull policy and several namespace options. Anything else is listed in a comment at the top.

### What happens to --rm and -d?

Compose has no key for --rm, so it is listed as not converted. -d does not need a key, because docker compose up -d starts services in the background.

### How are named volumes and networks handled?

A volume source that is a plain name, such as data in -v data:/var/lib/data, is declared under the top-level volumes key. A user-defined network is declared under networks as external, because docker run expects the network to exist already.

### How is the service named?

The service takes the value of --name when it is set, otherwise the image name without its registry and tag, so ghcr.io/acme/api:2 becomes api.

### Why are ports quoted?

Compose reads ports as strings, and some YAML parsers read unquoted values such as 22:22 as numbers in base 60. Quoting them avoids that, as the Compose documentation recommends.

### Can it convert several commands at once?

No. Paste one docker run command at a time and combine the services under one services key yourself.

Your ad here?

[Email us](mailto:hi@dennn.is?subject=Advertising%20on%20OneClick%20Pro)

[Ad 433 tools for your AI agents through one MCP server.](https://multitaskai.com/?ref=oneclickpro)
