Docker Compose Tip #88: Reversing a Compose file with docker compose alpha generate

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. ...

September 21, 2026 · 3 min · 440 words · Guillaume Lours