Build from a local build context, using a Dockerfile from stdin¶
# create a directory to work in
mkdir example
cd example
# create an example file
touch somefile.txt
# build an image using the current directory as context, and a Dockerfile passed through stdin
docker build -t myimage:latest -f- . <<EOF
FROMbusyboxCOPY somefile.txt ./
RUN cat /somefile.txt
EOF
# syntax=docker/dockerfile:1FROMgolang:1.16-alpineASbuild# Install tools required for project# Run `docker build --no-cache .` to update dependenciesRUN apk add --no-cache git
RUN go get github.com/golang/dep/cmd/dep
# List project dependencies with Gopkg.toml and Gopkg.lock# These layers are only re-built when Gopkg files are updatedCOPY Gopkg.lock Gopkg.toml /go/src/project/
WORKDIR /go/src/project/# Install library dependenciesRUN dep ensure -vendor-only
# Copy the entire project and build it# This layer is rebuilt when a file changes in the project directoryCOPY . /go/src/project/
RUN go build -o /bin/project
# This results in a single layer imageFROMscratchCOPY --from=build /bin/project /bin/project
ENTRYPOINT["/bin/project"]CMD["--help"]