Docker Compose to docker run converter

Turn a docker-compose.yml into docker run commands, with the docker network create, volume create and build lines each service needs.

loading Docker Compose to docker run converter
About this tool

What does converting docker-compose to docker run do?

A docker-compose.yml is the comfortable way to describe a stack, but sometimes Compose is not there. You are on a server with only the Docker engine, you want to see exactly what a compose service does, you are writing a README for people who do not use Compose, or you need a one-off command for a script. This converter reads a compose file and writes the docker run commands that start the same containers.

Every service becomes one command. image goes at the end, ports become -p, environment becomes --env, volumes become -v, restart becomes --restart, container_name becomes --name, and healthchecks, limits, logging, ulimits, capabilities and extra hosts have their own flags. A service with build first gets a docker build line that tags the image. Networks and named volumes the services need are created first with docker network create and docker volume create. Services are written in start order, so a service that another one depends on comes first.

Some things have no docker run flag, and the tool tells you instead of guessing: depends_on, profiles, configs, secrets and deploy.replicas. The conversion runs in your browser. Your compose file, which often holds passwords, is not uploaded. If you need the opposite direction, use the docker run to compose converter.

How to convert docker-compose to docker run

  1. Paste your file in the first box. It opens with an example of a Postgres database and an nginx web server, so you see a result before you type. Version 1 files, with services at the top level, are read too.
  2. The commands appear on the right as you type. The counter below says how many are ready.
  3. Choose the options above the box: Run in the background (-d), Remove on exit (--rm), One option per line, and Create networks and volumes. When One option per line is on, pick the line continuation character: Bash \, PowerShell ` ` or cmd ^`.
  4. Read the notices under the result. A yellow notice is something that was left out or needs your attention. A plain one is good to know, for example that a build line was added.
  5. Copy the result, or download it as docker-run.sh.

To check the compose file before converting it, use the Docker Compose validator. To run the same stack on a cluster, see the Docker to Kubernetes converter.

Examples

The default example

The example file has a db service with a healthcheck and a named volume, and a web service that depends on db and joins the front network. The output, with the default options:

docker network create front
docker volume create pgdata

docker run \
  -d \
  --name db \
  --restart unless-stopped \
  --env POSTGRES_PASSWORD=example \
  -v pgdata:/var/lib/postgresql/data \
  --health-cmd 'pg_isready -U postgres' \
  --health-interval 10s \
  --health-retries 5 \
  postgres:16

docker run \
  -d \
  --name web \
  --network front \
  -p 8080:80 \
  nginx:1.27

The notice says that depends_on (db) has no docker run flag. The commands are written in start order and you run them in that order.

One line per command, with a build

A service with build and a variable from your environment, with Run in the background off, Remove on exit on and One option per line off:

services:
  app:
    build: { context: ./app, dockerfile: Dockerfile.prod }
    depends_on: [db]
    environment:
      - DB=postgres://${DB_USER}@db
  db:
    image: postgres:16
docker run --rm --name db postgres:16

docker build -t app:latest -f Dockerfile.prod ./app
docker run --rm --name app --env "DB=postgres://${DB_USER}@db" app:latest

The build line tags the image app:latest and the run line uses that tag. The ${DB_USER} stays a shell variable inside double quotes, so your shell fills it in. Compose would read it from the environment or a .env file.

PowerShell line breaks

With the continuation set to PowerShell, a service with one port becomes:

docker run `
  -d `
  --name a `
  -p 80:80 `
  img

Choose cmd to get ^ at the end of each line instead. Turn One option per line off to get a single line that you can paste anywhere.

Long syntax and networks

The long form of ports and volumes is understood. { target: 80, published: 8080, protocol: udp, host_ip: 10.0.0.1 } becomes -p 10.0.0.1:8080:80/udp, and a bind mount with read_only: true becomes -v /srv:/data:ro. Networks with settings are created with their options, for example docker network create --subnet 172.20.0.0/16 front. Docker run joins one network, so the others are joined with docker network connect back a after the container starts.

Common errors and how to fix them

  • This is not valid YAML (line 3, column 5): the message gives the position and the reason. Check the indentation, use spaces and not tabs, and close every quote.
  • A compose file is a YAML map with a services section: you pasted a list or a single value. Start the file with services:.
  • No services found: add a services: section with at least one service that has an image or a build.
  • This service has neither image nor build: the command has <image> where the image name goes. Fill it in.
  • {key} has no docker run equivalent and was left out: the key exists in Compose but not in docker run, so it is dropped. Check that you do not need it.
  • {key} is not a service key this converter knows: usually a typo. Check the name with the Docker Compose validator.
  • {n} replicas cannot be set in docker run: run the command once per replica, with a different --name and port.

Frequently asked questions

How do I convert docker-compose to docker run?

Paste the compose file, choose the options and copy the commands. Run the network and volume lines first, then each service in the order shown.

Is the result the same as running docker compose up?

For the options that have a flag, yes: the containers are configured the same way. One difference is naming. With docker run, a named volume has exactly the name in the file, while Compose would have called it projectname_volume. A notice tells you.

What happens to depends_on?

There is no flag for it. The tool orders the commands so dependencies start first. It does not wait for a database to be ready. If you need that, use Compose or add a retry in the app.

Can I run the commands in PowerShell or cmd?

Yes. Choose the continuation character that your shell uses. Values are quoted for Bash, so in PowerShell or cmd check any value that contains spaces, $ or quotes.

How to run the result

Bash

bash docker-run.sh      # run everything in order
docker ps               # check that the containers are up
docker logs -f db       # follow one container
docker rm -f web db     # stop and remove them
Report a problem