How to Create Dockerfiles with GenAI
Framing Dockerfile generation as an interaction between an LLM and tools, rather than a chat where the user supplies project details, produces much better results. An assistant given analyze_project, write_files and docker_scout_tag_recommendation functions, two anchoring instructions, and Markdown best-practice prompts for NPM projects generates a three-stage Dockerfile with current slim base images and npm cache mounts, instead of an outdated single-stage node:14 file. The full transcript shows the GPT-4 assistant recovering on its own from an invalid-JSON tool error. Docker is still testing whether this approach adapts to new project types more easily than code templates.
Related posts
- Getting Started with the Labs AI Tools for Devs Docker Desktop Extension
Docker mediumAdeptThe Labs AI Tools for Devs Docker Desktop extension runs LLM prompts against local projects. Prompts are referenced by git ref or URL, or loaded as local files. A prompt is a markdown file with system and user sections, and project context such as languages and files is injected through mustache templates. Tools the LLM can call are defined as Docker images that get bind-mounted into the project and receive a JSON payload as their first argument. Sample prompts cover Dockerfile generation, runbooks, ESLint and Pylint fixes.
- ReadMeAI: An AI-powered README Generator for Developers
Docker mediumAdeptReadMeAI, an honorable mention from Docker's AI/ML Hackathon, generates a draft README from an uploaded code file and a short project description. It is a Node.js/Express app: the code and a prompt template go to Google's PaLM API, the Markdown that comes back is converted to HTML with showdown and rendered into an EJS editor view with live preview, and the result downloads as a zip of Markdown and HTML. The walkthrough covers the controller code, the project layout, and building and running the app with Docker.
- Using Docker AI Tools for Devs to Provide Context for Better Code Fixes
Docker mediumAdeptLLMs fix lint violations far better when given the surrounding code, so Docker Labs built a prompt-driven pipeline where each step runs in a container: Pylint produces a violation report, violations are loaded into SQLite, and Tree-sitter parses the project into an AST whose top-level statement ranges are indexed alongside the source. The LLM then queries this database (writing its own SQL from the schema) to retrieve the enclosing function for a violation before proposing a fix. This sidesteps context-window limits of reading whole files, and the same pattern generalizes to any tool that maps code locations to issues.
- Using AI Tools to Convert a PDF into Images
Docker mediumAdeptAn LLM agent can convert a PDF into JPEG images by planning an ImageMagick `convert` call that runs in a Docker container, so nothing needs to be installed locally. Tools are defined in Markdown prompt files, distributed through Docker Hub and pulled from nixpkgs. Rather than hand-designing interfaces for each tool, the agent loops through running the tool, capturing errors, reading the tool's own documentation and retrying. One packaging gap, a missing Ghostscript dependency, still had to be fixed by hand in the image build.
- Building a News Roundup with Docker Agent, Docker Model Runner, and Skill
Docker mediumAdeptA local news-roundup agent pairs a Docker Agent skill that queries the Brave Search API with Qwen3.5-4B (Unsloth Q4_K_M GGUF) served by Docker Model Runner, which handles reasoning and tool calls and writes a structured Markdown report. The setup uses a minimal Ubuntu Dockerfile with the docker-agent binary and a generic script toolset that runs shell commands, so the agent instructions stay light. A SKILL.md file defines the search, per-article enrichment and report-writing steps, and compose.yml wires in the model with a 65536-token context. It runs slower than Claude Code but stays local and costs no API credits; the 9B model was too slow on a MacBook Air.