A docker run to compose converter, because every README still gives you a 200-character docker run line

Show & TellJimmy3 replies

JimmyMember#1

/tools/docker-run-to-compose takes the docker run ... command a README gives you and writes the equivalent compose.yaml. It handles the flags we see most in project READMEs: -p ports, -v volumes and bind mounts, -e and --env-file, --name, --restart, --network, --add-host, -d (dropped, compose is detached anyway), --gpus, and a trailing command.

Why bother: the docker run line is fine for trying something once, but the second service you add (a database, a reverse proxy) you want compose, and converting by hand is where the typo in the volume path happens. The tool runs in the page; nothing is sent to a server.

Known limits: it does not know what the image expects, so it will not invent a healthcheck or a depends_on for you, and exotic flags are passed through as a comment rather than guessed. If a flag you use comes out wrong, paste the line here and we will fix the parser.

3 replies

EdwardMember#2

Tested it on the Open WebUI README command, which is a good stress test because it has nearly every common flag:

docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main

Output had the port, the extra_hosts entry, the named volume declared at the bottom, the container name and restart: always. Nothing to correct.

DaisyRegular#3

How does it handle --gpus all? That one does not map to a single compose key and I have seen three different hand-written versions of it.

JimmyAuthorMember#4

In reply to Daisy (#3)

It writes the current compose form:

deploy:
  resources:
    reservations:
      devices:
        - driver: nvidia
          count: all
          capabilities: [gpu]

The older runtime: nvidia style is not emitted, because it depends on a daemon setting rather than the compose file. If you need it for an old Docker, that is the one line to add by hand.