Docker Run to Docker Compose Converter

Paste a docker run command and get an equivalent docker-compose.yml. Ports, volumes, environment variables, labels, networks and resource limits are translated into Compose syntax, so a stack that grew as a long command line can be managed from a file that is easy to review and to copy between environments.

docker run command

docker-compose.yml


            
            

Ready — paste some input or load the sample.

100% Client-Side · Privacy First. This tool runs entirely inside your browser. Nothing you type is uploaded, logged or sent to a server — you can even use it offline.

Overview

Teams rarely start with a compose file. Somebody runs the container by hand, the command grows to four lines, and eventually nobody remembers which port was published or which directory was mounted. This converter turns that command into a real compose service so the container can be versioned, reviewed and started on a different machine. The output is ordinary compose YAML: a services block with the image, a ports list, an environment list, a volumes list and the options that have a direct compose equivalent. Flags that only make sense for a one-off run — detach, remove-on-exit — are reported in the notes panel instead of being silently dropped, and anything the converter cannot express is listed explicitly so nothing disappears without a trace.

How to use the docker run to docker compose converter

  1. 1Copy the docker run command from your shell history or from a deployment script.
  2. 2Paste it into the input panel — the image name is detected automatically and everything before it is treated as the container configuration.
  3. 3Read the notes panel, which lists every flag that had no exact Compose equivalent.
  4. 4Copy the YAML into a file named docker-compose.yml.
  5. 5Start the stack with docker compose up -d and check docker compose logs if the container does not come up.
  6. 6Add the volume and network declarations yourself if the stack needs named volumes instead of a plain bind mount.

Cheat sheet

The syntax you will use most, and what each part does.

PatternWhat it means
-p 8080:80 Becomes a ports entry such as "8080:80" under the service.
-e KEY=value Becomes an environment entry in the compose environment list.
-v ./data:/data Becomes a volumes entry; relative paths stay relative to the compose file.
--name myapp Becomes container_name, while the service key uses the name as well.
--restart unless-stopped Becomes the restart policy, which compose applies on every boot.
--memory 512m Becomes a deploy resources limit, the modern replacement for mem_limit.

Common mistakes

The command after the image is dropped.

Arguments such as nginx -g 'daemon off;' have no compose equivalent, so add them under command: or entrypoint: yourself.

Detached mode disappears.

Compose services always run in the background, so -d needs no counterpart in the file.

A relative volume path resolves differently.

Docker resolves ./data against your shell, compose resolves it against the compose file location.

Ports look like they are missing.

Check that the image really published them; -p only maps a port when the container process listens on it.

Worked examples

A simple web service

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

A service with image nginx:alpine, container_name web, ports 8080:80 and the NODE_ENV variable.

With a mounted volume and a network

docker run -p 5432:5432 -v pgdata:/var/lib/postgresql/data --network backend postgres:16

A service with a named pgdata volume, a published database port and the backend network declared.

Frequently asked questions

Is the docker run command sent anywhere?

No. The command is parsed locally in your browser, which matters because a real command line usually contains a password in an environment variable or a registry token in a login flag.

How are the port formats translated?

A -p flag becomes a ports list entry. The host and container sides keep their order, so -p 8080:80 becomes "8080:80", and a value that already contains a colon is copied through unchanged.

What happens to flags that Compose cannot express?

They are listed in the notes panel with a short explanation. The command that runs the image is the classic example, because Compose has no equivalent for an ad-hoc command override.

Does the generated file work with docker compose up straight away?

Yes, the output is a valid Compose file with a service, an image and a networks block. Add a volumes block yourself if you need named volumes that must survive a container replacement.

What happens to the -d flag?

It disappears, because Compose always starts in the background. That is one of the flags that needs no translation at all, and the notes panel says so.

How are environment variables handled?

An -e flag becomes an environment entry. A value without an equals sign is written as a bare key, which tells Compose to pass the value through from the shell it runs in.

Are relative volume paths safe?

They work, but the meaning changes. Docker resolves a relative bind mount against the current directory, while Compose resolves it against the directory that holds the Compose file, so mount the file the way the stack expects to run it.

Can I merge several docker run commands into one file?

Yes, convert each command separately and combine the service blocks, then give every service a unique container name and make sure the ports do not collide.

Do I still need the image name to be the last argument?

Yes, the image is what tells the converter where the flags stop and the image starts. A command that puts a flag after the image is interpreted as the command that runs inside the container.

How do I add a restart policy?

Use the --restart flag with a value such as unless-stopped or always. The converter maps it onto the restart key of the service, which is where Compose expects it.

Can I use a variable in the compose file?

Yes, and it is usually the better choice for an image tag. Declare the variable in a .env file next to the compose file and refer to it with the usual Compose variable syntax.