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.

More docker tools

Docker Container Image Reference Parser Is that a registry or a Docker Hub user? Dockerfile Linter What this image will do to you later docker run to Kubernetes YAML And the flags that have no equivalent Docker Compose to Kubernetes And why depends_on has no equivalent Docker Logging Driver Generator json-file never rotates Dockerfile Non-Root USER Generator Numeric, or Kubernetes rejects it Docker OCI Image Labels Generator One of them actually does something Docker Hub Pull Rate Limit Calculator Counted per IP, not per person Docker Registry Storage Calculator Deleting a tag frees nothing Docker Build Context Analyzer All of it uploads before anything runs Docker Compose to docker run Converter Names stop resolving Docker Compose Version Migrator version: is obsolete now Docker Compose Network and Port Viewer Everything reaches everything Docker Command Explainer Which flags hand over the host Docker BuildKit Cache Mount Generator apt deletes the cache you just mounted Docker BuildKit Secret Mount Generator ARG is in docker history forever Docker .dockerignore Pattern Tester *.log does not match logs/app.log Docker Image Manifest Viewer unknown/unknown is not broken Docker Image Config Viewer Anyone who can pull can read your Env Docker Registry Token Decoder Check the scope before the credentials Docker HEALTHCHECK Generator Docker does nothing when it fails Docker Network Subnet Calculator 31 networks, then it stops Docker History Analyzer The rm did not save anything Docker CMD and ENTRYPOINT Tester Why docker stop takes ten seconds Docker Port Mapping Tester -p reaches past your firewall Docker -v to --mount Converter -v invents missing directories Docker Restart Policy Simulator The backoff resets after ten seconds Docker Exit Code Explainer 137 is two different problems Docker CPU Limit Converter --cpu-shares limits nothing Docker Memory Limit Calculator -m 512m allows a gigabyte Docker Compose Interpolation Tester An unset variable is an empty string Docker Environment Variable Precedence Tester Your shell does not reach the container Docker Compose Override Merge Previewer An override can add a port, never remove one Dockerfile Multi-Stage Build Analyzer Which stages reach the image Dockerignore Validator It is not .gitignore

Elsewhere on the site