---
title: "How to Create Dockerfiles with GenAI"
description: "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."
url: "https://swe.quest/articles/how-to-create-dockerfiles-with-genai-c43e5eb0c85107c1"
canonical: "https://www.docker.com/blog/how-to-create-dockerfiles-with-genai/"
source: "Docker"
published: "2024-07-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["ai-agents","containers","llms","developer-tools"]
---

# How to Create Dockerfiles with GenAI

A post on [Docker](https://swe.quest/sources/docker.md), published 2024-07-29, 7 min read, How-to. Original: [https://www.docker.com/blog/how-to-create-dockerfiles-with-genai/](https://www.docker.com/blog/how-to-create-dockerfiles-with-genai/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Developer tools](https://swe.quest/tags/developer-tools.md) (Engineering practices)

## Prerequisites

- Dockerfile basics
- LLM function calling ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))

## Keywords

Docker, Dockerfile, GPT-4, Docker Scout, npm, multi-stage builds

## Related posts

- [Getting Started with the Labs AI Tools for Devs Docker Desktop Extension](https://swe.quest/articles/getting-started-with-the-labs-ai-tools-for-devs-docker-desktop-extension-82e61806b7468ca8.md): Docker · 2024-09-09 · Medium · 4 min read · AI agents, LLMs, Containers, Developer tools
  The Labs AI Tools for Devs Docker Desktop extension runs LLM prompts against local projects.
- [ReadMeAI: An AI-powered README Generator for Developers](https://swe.quest/articles/readmeai-an-ai-powered-readme-generator-for-developers-eb083158575e3617.md): Docker · 2024-06-28 · Medium · 10 min read · LLMs, Documentation, JavaScript, Containers
  ReadMeAI, an honorable mention from Docker's AI/ML Hackathon, generates a draft README from an uploaded code file and a short project description.
- [Using Docker AI Tools for Devs to Provide Context for Better Code Fixes](https://swe.quest/articles/using-docker-ai-tools-for-devs-to-provide-context-for-better-code-fixes-c0163de9f3027f93.md): Docker · 2024-10-21 · Medium · 8 min read · AI for coding, AI agents, Static analysis, Containers, Python
  LLMs 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.
- [Using AI Tools to Convert a PDF into Images](https://swe.quest/articles/using-ai-tools-to-convert-a-pdf-into-images-7d2ab149efe36a94.md): Docker · 2024-11-04 · Medium · 4 min read · AI agents, Containers, Developer tools, LLMs
  An 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.
- [Building a News Roundup with Docker Agent, Docker Model Runner, and Skill](https://swe.quest/articles/building-a-news-roundup-with-docker-agent-docker-model-runner-and-skill-93f611ba2590941a.md): Docker · 2026-03-27 · Medium · 6 min read · AI agents, LLMs, Containers, Inference & serving
  A 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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
