Skip to content

Instantly share code, notes, and snippets.

@vinceyoumans
Created December 11, 2018 21:27
Show Gist options
  • Save vinceyoumans/09e6464c9ab9382ad61f9cb3457820b2 to your computer and use it in GitHub Desktop.
Save vinceyoumans/09e6464c9ab9382ad61f9cb3457820b2 to your computer and use it in GitHub Desktop.
for the golang compile to a docker container
############################
# STEP 1 build executable binary
############################
FROM golang:alpine AS builder
# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git
COPY . $GOPATH/src/dock/v01
WORKDIR $GOPATH/src/dock/v01
# Fetch dependencies.
# Using go get.
RUN go get -d -v
# Build the binary.
#RUN go build -o /go/bin/v01
#RUN CGO_ENABLED=0 go build -installsuffix 'static' -o /app .
RUN CGO_ENABLED=0 go build -installsuffix 'static' -o /go/bin/v01 .
############################
# STEP 2 build a small image
############################
FROM scratch
# Copy our static executable.
COPY --from=builder /go/bin/v01 /go/bin/v01
# Run the hello binary.
ENTRYPOINT ["/go/bin/v01"]
# `docker run -p 80:80 <container>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment