docker run to Compose converter

The docker run to Compose converter turns one or more docker run commands into a Docker Compose file, with one service per command, and lists the flags that were not converted so you can complete them manually.
Input
Paste one or more docker run commands, each on its own line or after &&. A long command can be split over lines with \ at the end of the line. Up to 64 KB.

Conversion runs in your browser. Please enable JavaScript.

Everything runs in your browser; nothing is sent or stored.

  • Paste one or more commands in the "docker run commands" field, and the file updates as you type.
  • When the page loads, the input field contains two sample commands, and the file created from them appears in the "compose.yaml file" field.
  • The service name comes from the container name (--name) or, if there is none, from the image name. Named volumes are collected in the volumes section at the end of the file, and ports are written in quotes. Interactive mode (the -i and -t flags) becomes stdin_open and tty, and the command after the image name is kept as a list so that its quoting is preserved exactly.
  • Below the file, the tool shows notes about flags that were not converted, networks that need to be created in advance, and variables that were kept in the file.
  • Copy the file by clicking "Copy", and save it as compose.yaml in your project folder.

From a docker run command to a Compose file

The docker run command works well for starting a single container, but when you have several containers with ports, volumes, and environment variables, it is hard to remember all the commands and run them again. In a Compose file, each container is defined as a service, and all the settings are kept in one file that you can manage alongside your project code and start with the docker compose up -d command. During the conversion, each supported flag becomes the matching key in the file: -p becomes ports, -v becomes volumes, -e becomes environment, and --restart becomes restart.

Why ports are written in quotes

In YAML, an unquoted value such as 22:22 can be read as a base-60 number rather than as text, and as a result, Docker receives the wrong port mapping. The converter writes every port in quotes, such as "8080:80", so the mapping stays exactly as written in the command.

Passwords and environment variables in the file

Values passed with the -e flag, such as a database password, are written to the file as plain text. Before you save the file in a code repository, move the sensitive values to a .env file that is not included in the repository, and write a reference to the variable in the Compose file instead, such as ${POSTGRES_PASSWORD}. An -e flag with only a variable name is written to the file without a value, and Docker Compose takes the variable's value from the environment where it runs.

docker run flags and their result in a Compose file

  • -p 8080:80becomes the item "8080:80" in the ports list.
  • -v pgdata:/var/lib/postgresql/datapgdata is a named volume, so it is also added to the volumes section at the end of the file.
  • -v ./site:/usr/share/nginx/html:ro./site is a path on the host machine, so it is not added to the volumes section at the end of the file.
  • --network mynetthe network is added to the networks section at the end of the file and defined as an external network (external: true).
  • -itbecomes stdin_open: true and tty: true.
  • -e B='x$y'a $ sign inside single quotes is written as $$, and the value in the file is x$$y, so that Docker Compose does not replace $y with the value of a variable.
  • --rmthe flag has no equivalent in a Compose file, so it appears in the note about flags that were not converted.
Did you know?

With a Docker VPS, you can upload a Compose file to the server and start all of your application's services with a single command.

Docker VPS

docker run to Compose converter FAQ

Can I convert a command written for PowerShell or CMD?

You can convert a command copied from CMD or PowerShell, even when it is split over several lines. A line continuation is detected when a line ends with a backslash, the CMD ^ sign, or the PowerShell backtick. You can also paste commands that start with sudo or that are written as docker container run.

What happens to commands that are not docker run?

Other commands, such as docker pull or docker network create, are not converted, and their line numbers are shown in a note below the file. Lines that start with a # sign are treated as comments and are not processed.

Why is the network defined as external in the file?

The docker run command does not create a network, so a network named in the command was created in advance. The converter defines it in the file as an external network, which Docker Compose uses but does not create. When the network is used only by the services in the file, you can delete the external setting, and Docker Compose creates the network when it starts the services.

How do I handle flags that were not converted?

Flags that the converter does not convert, such as the flag for using a graphics processing unit (GPU), appear in a note below the file, and you need to add the matching setting manually, following the Docker Compose documentation. Flags that only change how the command runs, such as running in the background or removing the container when it exits, appear in a separate note and are not needed in the file.

Why is there no version field in the file?

The version field is obsolete in the Compose specification, so the converter does not add it to the file. A Compose file without this field is valid, and you can run it without any changes.

How many docker run commands can I convert at once?

You can convert up to 100 docker run commands at once, with an input of up to 64 KB.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement