Docker Run to Compose Converter

Turn a long docker run into a service definition. Some of what you typed describes how you were running the command rather than what the service is, and that part does not carry across.

Paste below, or drop a file anywhere on this panel

Or drop a file anywhere on this panel. Nothing is uploaded: the analysis runs in this tab.

The answer appears here

Paste on the left and press Convert. Nothing leaves this tab.

Examples

Real input you can load into the tool above. Each one shows a different thing going wrong, because that is what the tool is for.

A typical detached run

The -d does not carry across, and a restart policy is added

docker run -d --name web -p 8080:80 -e NODE_ENV=production -v /srv/data:/data nginx:alpine

A credential on the command line

Transient in shell history, permanent in a committed file

docker run -d --name api -e API_KEY=REPLACE_ME myapp:1

A privileged container

Carries across, and converting is a good moment to find out what it actually needed

docker run --privileged --name agent myagent:1

Common mistakes

These are the ones that fail silently. The config is accepted, nothing raises an error, and the consequence arrives later.

  1. Carrying -it and --rm into the compose file

    They describe the invocation. --rm has no equivalent, and stdin_open with tty on an ordinary service is noise that occasionally changes behaviour.

    Instead:Drop them. Use docker compose up -d to detach.

  2. Leaving the service with no restart policy

    docker run defaults to no restart, so a compose service converted verbatim stays down after any exit or reboot.

    Instead:Add restart: unless-stopped unless it really is a one-off.

  3. Pasting -e values straight into the file

    A value that lived in shell history is now committed and shared with everyone who has the repository.

    Instead:Use environment: ['API_KEY=${API_KEY}'] with a gitignored .env, or env_file.

A compose file describes a service, not an invocation

--rm, -d and -it are all about the command you typed. None of them belongs in a file that describes what a service is, and one of them has no equivalent at all.

What does not carry across

--rm has no compose equivalent. -d is docker compose up -d, a property of how you start the stack. -it maps to stdin_open and tty, which are only meaningful for a service you deliberately attach to, and setting them on a normal service is noise.

A restart policy is worth adding

docker run defaults to no restart, which is right for a one-off command and wrong for a service in a file somebody will bring up and walk away from. unless-stopped survives a reboot and respects a deliberate stop, which is what most people mean.

network_mode is not a compose network

It attaches to something that already exists and is incompatible with the networks key and with links. Compose creates a network per project and puts every service on it, which is why most compose files have no network configuration at all.

A credential on a command line becomes a credential in a file

-e API_KEY=... was transient in shell history. In a compose file it is committed and shared. Reference it instead, with the value in a gitignored .env, or use env_file.

Relative paths change meaning

docker run resolves a relative volume path against your current directory. Compose resolves it against the compose file's directory, so the same string can point somewhere else once converted.