docker compose alpha generate mycontainer --name myapp

Point that at a container that’s already running and it inspects it, then writes back the Compose file you’d otherwise have to write by hand. Tip #28 covered that translation manually; generate does it straight from what’s actually running.

What it produces

Run it against a container started with docker run -p 127.0.0.1:8080:80 nginx:alpine:

services:
  mycontainer:
    scale: 1
    image: nginx:alpine
    environment:
      PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      NGINX_VERSION: "1.31.5"
    labels:
      maintainer: "NGINX Docker Maintainers <docker-maint@nginx.com>"
    ports:
      - host_ip: "127.0.0.1"
        target: 80
        published: "8080"
        protocol: tcp

It reads networks, volumes, and healthchecks the same way, and --format json swaps the output format if you’d rather feed it into other tooling. Note the environment and labels above: they include everything baked into the image, not just what you passed on the command line. Useful for capturing what a container actually runs with, but expect to trim the output before committing it.

Why it matters

generate is listed alongside viz as one of the two commands currently under docker compose alpha, which means Compose is upfront that it’s still being built: flags, output shape, and behavior can all change release to release, no deprecation notice required.

That’s worth reading as an opportunity rather than a warning. Alpha commands are small, self-contained, and still taking shape, exactly the kind of code a first-time contributor can read start to finish and reason about. Trying one against a real stack and comparing the output to what you expected is the fastest way to find something worth reporting.

Pro tip: alpha bugs are normal, and they’re your ticket in

The example above pins a host IP, which is why host_ip comes out clean. Skip that (docker run -p 8080:80, bound to every interface, the more common case) and generate writes host_ip: invalid IP into the port entry instead of defaulting to 0.0.0.0:

ports:
  - host_ip: invalid IP
    target: 80
    published: "8080"
    protocol: tcp

The line responsible calls .String() on Go’s netip.Addr, and the zero value of that type stringifies to literally "invalid IP" rather than an empty string. It reproduces on the current release, not just an in-progress build, and there’s no open issue for it yet.

That’s the whole point of poking at alpha commands: bugs like this are expected, not embarrassing, and small enough to fully understand from the code alone. CONTRIBUTING.md covers the process, commits need a git commit -s sign-off, and docker compose alpha --help stays the source of truth for what’s currently in there to try.

Further reading