Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
Created February 18, 2019 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timjonesdev/69d888f180e8ca5e13f6cb548ad96c9e to your computer and use it in GitHub Desktop.
Save timjonesdev/69d888f180e8ca5e13f6cb548ad96c9e to your computer and use it in GitHub Desktop.
A Composite Dockerfile
# -------------------------------------------------------
# Build the go source
# -------------------------------------------------------
FROM docker.io/golang:1.11 as go-builder
# copy simple go application into the container
COPY app/api/main.go $GOPATH/src/app/main.go
# change the working directory, for convenience
WORKDIR $GOPATH/src/app
# build the Go binary and create some directories to copy in later stages
RUN CGO_ENABLED=0 go build -o /go/bin/app ./main.go && \
echo "App built"
# -------------------------------------------------------
# Put the go source into the scratch_and_sniff base image
# -------------------------------------------------------
FROM scratch_and_sniff
# copy source files from go-builder stage into the scratch container
COPY --from=go-builder /go/bin/app /usr/bin/app
# change working directory, so CMD is brief
WORKDIR /usr/bin/
# run the Go application
CMD ["app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment