Table of Contents
Fetching ...

Refactoring for Dockerfile Quality: A Dive into Developer Practices and Automation Potential

Emna Ksontini, Meriem Mastouri, Rania Khalsi, Wael Kessentini

TL;DR

This work investigates automating Dockerfile refactoring using In-Context Learning (ICL) with a large, diverse corpus of Dockerfiles. By combining a score-based demonstration retrieval strategy and zero-/few-shot prompts, the approach yields substantial gains in image size reduction (up to ~32%) and build-time reductions (up to ~6%), while improving maintainability (≈91%) and understandability (≈77%). Automated refactoring outperforms manual refactoring and smell-only tools (e.g., PARFUM), achieving much larger image-size reductions and higher build-success rates, though build failures remain a risk due to context and dependency issues. The study also analyzes refactoring habits, lifecycle trends, and failure modes, highlighting the potential for integrating automated Dockerfile refactoring into CI/CD pipelines to continuously improve Dockerfile quality across the software lifecycle.

Abstract

Docker, the industry standard for packaging and deploying applications, leverages Infrastructure as Code (IaC) principles to facilitate the creation of images through Dockerfiles. However, maintaining Dockerfiles presents significant challenges. Refactoring, in particular, is often a manual and complex process. This paper explores the utility and practicality of automating Dockerfile refactoring using 600 Dockerfiles from 358 open-source projects. Our study reveals that Dockerfile image size and build duration tend to increase as projects evolve, with developers often postponing refactoring efforts until later stages in the development cycle. This trend motivates the automation of refactoring. To achieve this, we leverage In Context Learning (ICL) along with a score-based demonstration selection strategy. Our approach leads to an average reduction of 32% in image size and a 6% decrease in build duration, with improvements in understandability and maintainability observed in 77% and 91% of cases, respectively. Additionally, our analysis shows that automated refactoring reduces Dockerfile image size by 2x compared to manual refactoring and 10x compared to smell-fixing tools like PARFUM. This work establishes a foundation for automating Dockerfile refactoring, indicating that such automation could become a standard practice within CI/CD pipelines to enhance Dockerfile quality throughout every step of the software development lifecycle.

Refactoring for Dockerfile Quality: A Dive into Developer Practices and Automation Potential

TL;DR

This work investigates automating Dockerfile refactoring using In-Context Learning (ICL) with a large, diverse corpus of Dockerfiles. By combining a score-based demonstration retrieval strategy and zero-/few-shot prompts, the approach yields substantial gains in image size reduction (up to ~32%) and build-time reductions (up to ~6%), while improving maintainability (≈91%) and understandability (≈77%). Automated refactoring outperforms manual refactoring and smell-only tools (e.g., PARFUM), achieving much larger image-size reductions and higher build-success rates, though build failures remain a risk due to context and dependency issues. The study also analyzes refactoring habits, lifecycle trends, and failure modes, highlighting the potential for integrating automated Dockerfile refactoring into CI/CD pipelines to continuously improve Dockerfile quality across the software lifecycle.

Abstract

Docker, the industry standard for packaging and deploying applications, leverages Infrastructure as Code (IaC) principles to facilitate the creation of images through Dockerfiles. However, maintaining Dockerfiles presents significant challenges. Refactoring, in particular, is often a manual and complex process. This paper explores the utility and practicality of automating Dockerfile refactoring using 600 Dockerfiles from 358 open-source projects. Our study reveals that Dockerfile image size and build duration tend to increase as projects evolve, with developers often postponing refactoring efforts until later stages in the development cycle. This trend motivates the automation of refactoring. To achieve this, we leverage In Context Learning (ICL) along with a score-based demonstration selection strategy. Our approach leads to an average reduction of 32% in image size and a 6% decrease in build duration, with improvements in understandability and maintainability observed in 77% and 91% of cases, respectively. Additionally, our analysis shows that automated refactoring reduces Dockerfile image size by 2x compared to manual refactoring and 10x compared to smell-fixing tools like PARFUM. This work establishes a foundation for automating Dockerfile refactoring, indicating that such automation could become a standard practice within CI/CD pipelines to enhance Dockerfile quality throughout every step of the software development lifecycle.
Paper Structure (18 sections, 1 equation, 7 figures, 2 tables)

This paper contains 18 sections, 1 equation, 7 figures, 2 tables.

Figures (7)

  • Figure 1: Approach overview and addressed RQs (RQ1: yellow arrows, RQ2: green arrows, RQ3: blue arrows, and RQ4: red arrows)
  • Figure 2: Mean Image Size & Build Duration Increase Over Project Lifecycle
  • Figure 3: Cumulative percentage of Dockerfiles with first refactoring commit.
  • Figure 4: Mean proportion of refactoring commits across project lifecycles.
  • Figure 5: Refactoring Techniques Distribution
  • ...and 2 more figures