A small, self-correcting loop. A local model (via Ollama) writes a Dockerfile, docker build decides whether it works, and when it doesn't, the model gets its previous Dockerfile plus the tail of the build error and tries again. A successful build is the only thing that counts as success.
- Inspect the project: top-level files and the first dependency manifest found (
requirements.txt,pyproject.toml,package.json,go.mod,Cargo.toml,Gemfile). - Generate a Dockerfile with fixed rules in the prompt: pinned base image, dependencies installed before the source is copied, non-root user where possible, explicit start command.
- Build it with
docker build. - Correct: on failure, the next prompt carries the previous Dockerfile and the last 40 lines of build output. Repeat up to
--attemptstimes.
Each Dockerfile is printed before it is built. Before building, check_dockerfile refuses features that reach beyond a plain build (see Safety); a refused Dockerfile is not built, and the refusal reason goes back to the model as a failed attempt.
An existing Dockerfile in the project is backed up (Dockerfile.bak-<timestamp>, with -1, -2… added if that name is taken) before anything is written; backups are never overwritten and are left out of the prompt.
ollama pull qwen2.5-coder:7b
python3 dockergen.py samples/flask-app
python3 dockergen.py path/to/app --model qwen2.5-coder:1.5b --attempts 5
python3 dockergen.py path/to/app --network none # RUN steps get no network
python3 dockergen.py path/to/app --dry-run # write and print one Dockerfile, build nothing| Option | Default | Meaning |
|---|---|---|
--model |
qwen2.5-coder:7b |
Ollama model name |
--url |
http://localhost:11434/api/generate |
Ollama endpoint |
--attempts |
3 |
generate/build rounds before giving up |
--tag |
dockergen-test |
image tag for test builds |
--network |
default |
network for RUN steps during the build: default or none |
--dry-run |
off | write and print one Dockerfile, do not build it |
--llm-timeout, --build-timeout |
300, 900 s |
per-call limits |
| Exit code | Meaning |
|---|---|
0 |
a Dockerfile was written and built (with --dry-run: written and printed, not built) |
1 |
every attempt failed to build or was refused by check_dockerfile (with --dry-run: the one Dockerfile would be refused); the last Dockerfile is left for inspection |
2 |
usage or setup error: not a directory, --attempts below 1, Docker not on PATH or its daemon unreachable, Ollama unreachable or its reply malformed or empty, Dockerfile is a symlink |
- The model's
RUNsteps execute.docker buildruns everyRUNline the model writes, on your machine, inside the build container. Use dockergen on projects you trust and read the Dockerfile it prints before each build. --network nonegivesRUNsteps no network, so they cannot download or send anything. Base images are still pulled. Builds that install dependencies at build time (pip install,npm install,go mod downloadwith real modules) will fail under it.--dry-runwrites and prints one Dockerfile and builds nothing, so you can review it first.- Refused features. A Dockerfile is not built if it uses a
# syntax=directive (custom BuildKit frontend),--mount=,--network=or--security=flags, orADDfrom anhttp(s)://URL. - Symlinks. A
Dockerfilethat is a symlink stops the run (exit 2) and the file is written withO_NOFOLLOW. A dependency manifest that is a symlink or resolves outside the project is skipped, so it never reaches the prompt. COPY . .copies everything in the project directory, including files like.env, unless a.dockerignoreexcludes them. The image stays local, but check before you push it anywhere.- Remote
--url. The prompt (top-level file names, one dependency manifest, and on retries the previous Dockerfile and build output) goes to whatever--urlpoints at. dockergen warns when the host is notlocalhost,127.0.0.1or::1.
No third-party Python packages are needed; the tool uses only the standard library.
samples/ holds three minimal "hello" services to try it on: Flask (flask==3.0.3), Express (express 4.18.2) and Go's net/http (Go 1.21).
- Original runs with
qwen2.5-coder:7b(September 2026) are recorded in FAILURES.md, including the Node.js.dockerignorecorrection. - November 2026, with this version and the much smaller
qwen2.5-coder:1.5bon a copy of the Go sample (--network none,--attempts 3): the build succeeded on the first attempt (exit 0). The image it built did not start: the Dockerfile setUSER go, which does not exist in the Alpine base image (docker runexit 125). That is the "built, not run" limit below in practice. A--dry-runon another copy wrote and printed a Dockerfile and built nothing (exit 0). qwen2.5-coder:7b, the default model, has not been re-tested with this version.
python3 -m pytest -q testsThe tests run offline: the model and docker build are replaced by fakes, so they check the loop itself (retry prompt contents, error truncation, backups that never overwrite, exit codes 0/1/2 from main()), reply parsing (fence variants, empty and malformed Ollama replies), the safety checks (each refused pattern, refused Dockerfiles never built, symlinks, --dry-run, the remote --url warning) and the sample manifests. CI runs them on every push with read-only permissions and SHA-pinned actions.
- One project directory at a time; monorepos need a path per service.
- Success means the image built; dockergen never runs the image. Build-time
RUNsteps do execute (see Safety), but the app's start command is never tried, so a build that succeeds can still produce an image that does not start. - The prompt sees file names and one manifest, not the source code.