Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: INCLUDE directive in Dockerfile for code deduplication #5824

Open
kasperk81 opened this issue Mar 8, 2025 · 0 comments
Open

Comments

@kasperk81
Copy link

Description

Summary
Introduce an INCLUDE directive in Dockerfile syntax to allow inclusion of external file fragments. This would help reduce code duplication and improve maintainability.

Motivation
Dockerfiles often contain repetitive commands or similar configurations. By enabling an INCLUDE directive, developers could.

Proposed Implementation

  • Syntax:
    INCLUDE path
  • Behavior:
    The contents of the specified file should be read and inserted at the point of the INCLUDE directive. All build-time variables (e.g., ARGs, ENV variables) in scope should be accessible within the included content.

Example Usage
Given the following Dockerfile:

FROM alpine

ARG filename
ARG myvar

RUN echo "Before including ${filename}, it will inherit ARGs from this file"

INCLUDE ${filename}

RUN echo "After including ${filename}"

And a file named template.txt containing:

RUN echo "here we can access myvar: ${myvar} and filename: ${filename}"

Building with:

docker build . --build-arg filename=template.txt --build-arg myvar=foo

The existing alternatives like https://codeberg.org/devthefuture/dockerfile-x do not work with arg, they omit everything before the INCLUDE line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant