Skip to content

Proposal: docker build read Dockerfile from stdin #27393

@dsheets

Description

@dsheets

I propose that docker build accept -f - to indicate that the Dockerfile to be used is read from the STDIN of the docker client process.

Use cases

  • Shared engine CI systems can now stack anonymous image builds easily without requiring intermediate directories or tar archives
  • Dockerfiles in local directories, tar archives, and git repos can now be overridden
  • docker build is now a versatile shell scripting command as Dockerfiles can participate in shell pipelines decoupled from file system contexts

New capabilities

  • Uncooperative remote tar archives and git repos can now have out-of-band Dockerfiles applied to them
  • Local directory builds can now have Dockerfiles imported for just the build via I/O redirection

Design considerations

  • A - stdin reader interface already exists in the context path argument so any -f - implementation will have to accommodate that
  • Accepting - in place of file paths is a common UNIX idiom to indicate that what would have been read from the path specified should instead be read from stdin; this makes having docker participate in UNIX pipelines much easier
  • This feature could be abused to avoid Best Practice so all advice regarding application/system design should be maintained and users should be encouraged to place Dockerfiles in repositories and tarballs so builds are straightforward and unambiguous when possible

Cases

  • builder.GetContextFromReader (builder/context.go) is used to read a context (or Dockerfile only) from stdin: nothing will change, a file called - will still be sourced from the stdin tarball (or still ignored in the case of Dockerfile only on stdin)
  • builder.GetContextFromGitURL (builder/context.go) is used to read a context from a git URL and the resultant context will have its Dockerfile rewritten and used for the build
  • builder.GetContextFromURL (builder/context.go) is used to read a context from a remote URL and the resultant context will have its Dockerfile rewritten and used for the build (or ignored in the case of a Dockerfile only context)
  • builder.GetContextFromLocalDir (builder/context.go) is used to read a context from a local directory and the resultant context will have its Dockerfile rewritten and used for the build

Implementation

I've prototyped this functionality by rewriting the tar stream of the context before the trusted pull rewriting. If there is interest in this functionality, I will clean up my prototype and submit a PR. I welcome your ideas regarding this or similar features. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/builderBuildkind/featureFunctionality or other elements that the project doesn't currently have. Features are new and shiny

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions