multidockerfile
is a command-line tool that allows you to split multi-stage Dockerfiles into multiple files.
Multi-stage builds are a powerful way to optimize Dockerfiles, especially when combined with docker buildx bake
to build multiple images in parallel.
However, Docker requires that all stages are defined in a single Dockerfile, which can become difficult to navigate as it grows.
With multidockerfile
, you can split the Dockerfile up, and recombine it with multidockerfile join
before building the images.
multidockerfile
parses the individual Dockerfiles looking for the FROM
and COPY --from
instructions that create dependencies between stages.
The combined Dockerfile is sorted so that stages with dependencies appear after the stages on which they depend.
Pre-built binaries are available for each release.
You can download the correct version for your operating system, make it executable with chmod +x
, and either execute it directly or put it on your path.
SHA-256 checksums and GPG signatures are available to verify integrity. My GPG public key can be obtained from
GitHub (@haines)
$ curl https://github.com/haines.gpg | gpg --import
Keybase (haines)
$ curl https://keybase.io/haines/pgp_keys.asc | gpg --import
keys.openpgp.net ([email protected])
$ gpg --keyserver keys.openpgp.org --recv-keys 6E225DD62262D98AAC77F9CDB16A6F178227A23E
A Docker image is available for each release at ghcr.io/haines/multidockerfile.
Join multiple Dockerfiles into a single multi-stage Dockerfile.
Name | Description |
---|---|
<inputs> ... |
Paths to the Dockerfiles to be joined. |
Short | Long | Default | Description |
---|---|---|---|
-o |
--output |
- |
Where to write the multi-stage Dockerfile (- for stdout). |
# dockerfiles/one.dockerfile
FROM alpine AS one
# dockerfiles/two.dockerfile
FROM alpine AS two
$ multidockerfile join dockerfiles/*.dockerfile
FROM alpine AS one
FROM alpine AS two
Show the multidockerfile
version information.
$ multidockerfile version
{
"Version": "0.1.0-dev",
"GitCommit": "20586c3eb00aad3dde1ca63eb47dcb14ae6372d5",
"Built": "2021-02-26T21:22:04Z",
"GoVersion": "go1.16",
"OS": "darwin",
"Arch": "amd64"
}