Automatic Dockerfile Generation with Large Language Models
Jun Lyu, He Zhang, Yusong Yuan, Lanxin Yang, Yue Li, Manuel Rigger
Abstract
Project maintainers on platforms like GitHub usually provide a document (e.g., a Readme) describing how to build and use their software, whose instructions, often written in natural language, might sometimes be ambiguous or platform-specific. This task can be eased by containerization, which allows developers to define the build environments required for their software and to enable automatic builds. Docker is the leading platform in this field and relies on Dockerfiles for correct execution. Practitioners who want to use and build projects that do not include a Dockerfile need to develop it themselves. They often need to perform multiple builds by trial and error to discover the correct build steps and build dependencies (e.g., third-party library necessary for software builds). To address this challenge, we propose a novel approach and tool called Dockerfile Refinement and Fixing Tool (DRAFT), which can automatically generate a working Dockerfile by a Large Language Model (LLM). The core idea of DRAFT is that it emulates developers’ behavior iteratively. Specifically, DRAFT is used to iteratively generate prompts to instruct the LLM to generate patches for an initially generated Dockerfile until it executes successfully. Subsequently, it attempts to optimize the Dockerfile to reduce the size of the image it builds. We evaluated DRAFT on 35 projects and compared it with the Dockerfiles generated by Copilot (based on ChatGPT 4.0), Actions_remaker, Repo2docker, Boxing, and Starter in five different languages (C, Java, Go, Python, and Ruby). The evaluation results show that DRAFT can successfully generate Dockerfiles for 28 projects, resulting in a success rate of 80%, which is much higher than all compared tools. The time consumed by DRAFT on generating Dockerfiles is 19.57 minutes at maximum with the median at 33.78s. Using DRAFT can reduce image size by 67.14% and build time by 3.62%. DRAFT relieves practitioners from the burden of manually creating build specifications.
Ask about this paper
Ask your agent about it.
Lune has read the top-tier papers around this one, so every answer names the papers it rests on.
Your agent calls
Lunesearch_papers
Free to start. No credit card required.
Terminal
Install the CLIlune papers get 9104c82c-2bf9-4c8c-82e5-abb6385e4e51Related papers
- Shipwright: A Human-in-the-Loop System for Dockerfile RepairJordan Henkel, Denini Silva, Leopoldo Teixeira, Marcelo d'Amorim et al.ICSE 2021 · 31 citations
- From Exploration to Mastery: Enabling LLMs to Master Tools via Self-Driven InteractionsChangle Qu, Sunhao Dai, Xiaochi Wei, Hengyi Cai et al.ICLR 2025
- Automated Program Refinement: Guide and Verify Code Large Language Model with Refinement CalculusYufan Cai, Zhe Hou, David Sanán, Xiaokun Luan et al.POPL 2025 · 20 citations
- Dockerfile Flakiness: Characterization and RepairTaha Shabani, Noor Nashid, Parsa Alian, Ali MesbahICSE 2025 · 2 citations
- LLM-Based Method Name Suggestion with Automatically Generated Context-Rich PromptsWaseem Akram, Yanjie Jiang, Yuxia Zhang, Haris Ali Khan et al.FSE 2025 · 1 citation
